Languages
[Edit]
EN

Spring Boot 2 - receive response message for the request message using RabbitMQ (RPC)

6 points
Created by:
Creg
9600

In this article, we would like to show you how to create Spring Boot 2 application that sends request messages and receives response messages using RabbitMQ RPC pattern.

RabbitMQ RPC pattern in Spring Boot 2 application.
RabbitMQ RPC pattern in Spring Boot 2 application.

In Spring Boot 2 application using RabbitMQ RPC pattern, it is necessary to send message from producer to consumer attaching REPLY_TO and CORRELATION_ID headers, that indicate to consumer which producer by what action sent message.

 

Spring Boot 2 Applications

Edit

In this section, we can find a simplified solution that realizes the request-response pattern.

Hint: the article extends project in this article.

 

Producer application example

Edit

The main idea of the producer is to send messages using convertSendAndReceive() method.

ProducerController.java file:

Hint: if the time of the waiting for the response is long we can change timeout.

 

Consumer application example

Edit

The main idea of the consumer is:

  • listen for a request messages,
  • send a response message to the queue indicated in AmqpHeaders.REPLY_TO header that indicates the request message producer,
  • indicate proper correlation id parameter in the response message to let the producer know on what request message reply is sent.

ConsumerService.java file:

RpcService.java file:

 

References

Edit
  1. Direct Reply-to - RabbitMQ Docs

  2. Remote procedure call (RPC) - RabbitMQ Docs

Alternative titles

  1. Spring Boot 2 - RabbitMQ request and response message (Remote Procedure Call)
  2. Spring Boot 2 - RabbitMQ request-response pattern message (RPC)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join