Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring rabbit listen output queue or receive

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

like image 614
avalon Avatar asked Jan 31 '26 01:01

avalon


1 Answers

The second way as with the first way you will have to implement what the second way already does:

  • create a correlation id
  • maintain a map
  • dequeue message from the reply queue
  • correlate reply message with the producer
  • ...

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

like image 87
Nicolas Labrot Avatar answered Feb 01 '26 14:02

Nicolas Labrot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!