amqp中使用
provider使用sendAndReceive可以等待消费者取得返回值
consumer使用receiveAndReply,并添加监听器,可以取得provider的message处理并回复
当消息是异步时,直接注册监听器实现onMessage()方法即可。
但是onMessage()方法的返回值是void
那么如果要实现provider同步的功能
consumer除了
while(true){
amqpTemplate.receiveAndReply(queueName,new Callback(Message message){
dosomething;
return "result";
})
}
这种方式之外 还有别的使用方法吗?
Why do we have to wait for the return value?
A -> B
A <- B
A sends a message to B, and B receives and processes the message. B sends a message (receipt) to A when A receives the message processing result. AB is
Producer
也是Consumer
.If MQ still needs to do synchronization and other operations, wouldn't it be easier to use MQ directly and use the interface?
Then you want the provider to block until it receives the return value from the consumer?
This is not recommended. If you must receive synchronously, you can make both provider and consumer single-threaded.