[英]Subscribe specific message in RMQ message queue
I have a RM queue test-queue
.我有一个 RM 队列test-queue
。 In there I need to handle 3 separate messages ( message-1, message-2, message-3
) for 3 separate processes in 3 separate services.在那里,我需要为 3 个单独的服务中的 3 个单独的进程处理 3 个单独的消息( message-1, message-2, message-3
)。
I use @RabbitListener
like below to access the message我使用下面的@RabbitListener
来访问消息
@RabbitListener(queues = "test-queue")
public void getMessage1(Message message) {
System.out.println(message);
}
but I need to access specific message ex: message-1
only in this function.但我需要访问特定的消息,例如:仅在此 function 中的message-1
。
Any heads up?有什么注意的吗?
That's wrong design for AMQP protocol.这是 AMQP 协议的错误设计。 You need to think about 3 different queues for those messages and correct bindings for them from a single exchange with the proper routing.您需要为这些消息考虑 3 个不同的队列,并从具有正确路由的单个交换中为它们正确绑定。 Then you can easy have 3 consumers from those queues.然后,您可以轻松地从这些队列中获得 3 个消费者。
My point is that queue entity is a consumer responsibility.我的观点是队列实体是消费者的责任。 The producer just dump a message into an exchange.生产者只是将消息转储到交换中。 So, you just dictate from your consumer application how you'd like to get produced messages.因此,您只需从您的消费者应用程序中指定您希望如何获取生成的消息。
Out of subject you can investigate a Spring Integration router pattern implementation if you really can't change your RabbitMQ structure: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#messaging-routing-chapter Out of subject you can investigate a Spring Integration router pattern implementation if you really can't change your RabbitMQ structure: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html #messaging-routing-章节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.