java - spring-amqp中消费者同步回复消息有没有更简单的方法?
ringa_lee
ringa_lee 2017-04-18 10:26:20
0
2
516

amqp中使用
provider使用sendAndReceive可以等待消费者取得返回值
consumer使用receiveAndReply,并添加监听器,可以取得provider的message处理并回复

当消息是异步时,直接注册监听器实现onMessage()方法即可。
但是onMessage()方法的返回值是void

那么如果要实现provider同步的功能
consumer除了

while(true){
    amqpTemplate.receiveAndReply(queueName,new Callback(Message message){
         dosomething;
         return "result";
    })
}

这种方式之外 还有别的使用方法吗?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
刘奇

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!