I want a Synchronous API for Rabbit MQ in java like QueueingConsumer so that I can fetch message from the Rabbit MQ. But QueueingConsumer is now deprecated. Can anyone please tell me how can I write one of my own.
Reason for Synchronous Consumer - I am writing REST service which will fetch message from Queue and return it as a response.
I. As I understand, you are using of rabbitmq
java client. In this case you should do something like this:
correlationId
, replyTo
propertiesжcorrelationId
and replyTo
to your message;channel.basicPublish()
to queue/exchange (your destination);channel.basicConsume()
;channge.basicConsume()
just check correlationId
of incoming message.correlationId
is match – return received message;Full code example here .
Also you could find comprehensive answer to your question here .
II . If you need a ready-made solution I think you could useSpring AMQP library or any other high-level library. The list of libraries can be found here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.