Reputation: 4315
I am configuring an example to check if RabbitMQ can solve my problem and I am running to a problem.
The task: I have 3 machines behind gateway and only one of them has the necessary data to process the message. This I want to solve with condition check.
The problem: I tried to configure a few listeners to emulate the situation as if a few machines consume the message.
@RabbitListener(queues = "spring-boot")
public void receiveMessage1(String message) {
if(canProcess()){
System.out.println("Received 1 <" + message + ">");
}
}
@RabbitListener(queues = "spring-boot")
public void receiveMessage2(String message) {
if(canProcess()){
System.out.println("Received 2 <" + message + ">");
}
}
However, only one random listener processes the message. Others just don't get it. I there a way all listeners consume it and I myself decide which one processes it by "canProcess" method?
Upvotes: 1
Views: 1072
Reputation: 615
Other listeners doesnt process your message because it is consumed properly by one of them. After receivemessage method is end without errors rabbit listener internally marks your message as processed. It doesnt know your flow. So work around for this could be throwing an Exception when message cant be proccesed, but its ugly fix - its not very efficient way of handling messages.
I found this article which covers this type of architecture https://derickbailey.com/2015/07/22/airport-baggage-claims-selective-consumers-and-rabbitmq-anti-patterns/
Upvotes: 2