Spring queue to listen rabbit or receive
I am developing an app with rabbitmq support. So I have a consumer and a producer. And I need to decide between the two ways, how to set up the communication between them.
The first way
public void send(){
//send to consumer and forget
rabbitTemplate.convertAndSend("","routing-key",my object);
//waiting for output queue and messages from consumer
while(true){
//receive something.
if(corellationID==what we need){
//do what we need
break;
}
}
}
Second way
public void send(){
//send to consumer and wait for result
Object o=rabbitTemplate.convertSendAndReceive("","routing-key",my object);
}
Which path will run faster and more stable under high loads? And there might be another more efficient way to do it. Thanks you
+3
source to share
1 answer
The second way, as at first glance, you will have to implement what the second way already does:
- create correlation id
- save the map.
- dequeue message from response queue
- match the reply message with the manufacturer
- ...
Btw the most efficient way is no thread waiting for a response. and therefore works asynchronously: the thread that sends the message may not be the one that receives the response. Check the documentation
+3
source to share