Spring Boot + RabbitMQ implements RPC calls

O.cr
Geek Culture
Published in
4 min readMar 2, 2022

--

RabbitMQ is a queue handler, so it allows holding messages and reading them through another task. A more in-depth presentation will be made in another article. In this article, we will focus on an important concept in RabbitMQ: the RPC. An RPC (remote procedure call) allows you to send a message to a queue and wait for a response. To better understand this concept, let’s start with a simple example: the generation of an outsourced content URL. There is therefore a client that sends content to a RabbitMQ queue in order to know the generated URL. The client then only needs a “call” method.

Also in the client, initializing the callback queue lets the queued message know where to drop the reply message.

All messages posted to the queue will have a response in the callback queue. A problem remains: how to recognize each message in the callback queue? The idea is to put a unique key on each message that allows it to be recognized afterward.

The unique key is called the ‘correlation_id’, it identifies each response in relation to its message. It is sent on each message sent to the server and returned in the response which then makes it possible to recognize the initial request. Before doing the sample code, here is a small summary:

--

--

O.cr
Geek Culture

Entrepreneur | Full-stack Developer | React native enthusiast | Medium Writer.