I am developing an application with rabbitmq support. So, I have a consumer and a producer. And I need to decide between two ways how to set up communication between both of 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;
}
}
}
The second way
public void send(){
//send to consumer and wait for result
Object o=rabbitTemplate.convertSendAndReceive("","routing-key",my object);
}
Which way will work more quickly and stable under high loadings? And may be there another more effective way to do this. Thank you
The second way as with the first way you will have to implement what the second way already does:
Btw the most effective way is to not have a thread that waits for the reply. and so works in an asynchronous way: the thread that sends the message may not be the one that receive the reply. Have a look at the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With