Request-reply over a queue

RabbitMQ Course · lesson 10 of 15 · 5 min read

reply-to and correlation-id turn two one-way messages into a request-response call.

Open this lesson in the learning hub

Key points

  • The reply-to property names the queue for the answer and correlation-id pairs them up.
  • Direct reply-to consumes from amq.rabbitmq.reply-to, a pseudo-queue you never declare or delete.
  • Declaring a fresh exclusive reply queue per call is slow, so one reply queue per client is the usual fix.
  • The caller must time out itself - a broker hop hides the TCP failure a direct call would surface.
  • RabbitTemplate.convertSendAndReceive uses direct reply-to and a 5 second reply timeout.
  • Two extra hops buy nothing if the caller just blocks, so consider calling the service directly instead.

RPC over AMQP is two messages joined by a correlation id - the timeout is entirely yours to enforce.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the RabbitMQ Course course, and every lesson in it is listed on the RabbitMQ Course contents page.