Reactor RabbitMQ in your Reactive Spring Boot Application — Part 1

{getToc} $title={Table of Contents}


Spring Reactive & Reactor RabbitMQ API with a real-world example



Introduction

In this part 1, I'm going to show about RabbitMQ Message Broker Process and the microservice architecture with rabbitmq in this tutorial project that I'm going to build with spring boot reactor by using Spring WebFlux.


I'm using docker as the container for running RabbitMQ image in this tutorial  

I will do the final project demo in the beginning of this video too, then if it's what you're finding, so please continue to follow the next part...


What is rabbitmq?

RabbitMQ is a message broker: it accepts and forwards messages. You can think about it as a post office: when you put the mail that you want posting in a post box, you can be sure that the letter carrier will eventually deliver the mail to your recipient. In this analogy, RabbitMQ is a post box, a post office, and a letter carrier.


In this tutorial, I have introduced the new functional web framework, to use Spring Webflux (Spring WebFlux is a new functional web framework built using reactive principles.) to its full potential I believe it is better to move away from the controller annotation-based and move towards using functions to route and handle requests.



What is docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.


If you do not have docker & rabbitmq install on your operating system yet, then check this first: Get ready to install Docker, Erlang and RabbitMQ and running on Docker image on Window OS (khmerside.blogspot.com)


Body

Let's suppose that we have designed the architecture with 5 components need to be implement.

1. Client

2. API Gateway

3. Sender Service

4. Message Broker (RabbitMQ)

5. Receiver Service

RabbitMQ Message Broker Diagram


Demo Project


First, need to run docker demon on your os



Run RabbitMQ Command Prompt from your OS, and type this command to run build rabbitmq image on Docker.


# latest RabbitMQ 3.10
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.10.6-management

Go to this rabbitmq official size for the command: Downloading and Installing RabbitMQ — RabbitMQ

After run that command that, This means that the RabbitMQ will be listening on port 5672 and the management portal will be on 15672.

After the docker image has been up, please go to http://localhost:15672. 

You will be prompted to log in to the system. The username and password are both ‘guest



After you have logged in by using username/passworld guest, you will go to this page.




Now, let's start your sender service from application, in my case, I have set port 8001 for sender service to send message to RabbitMQ Broker. 



I will use postman tool to run sending service by using service endpoint which have set in the application on port 8001.



And that messages will be queue in RabbitMQ



And then, I will start up the receiver service to receive all the queue messages in the message broker (RabbitMQ). The receiver service is running on port 8002 in my case.



Now all the queue messages has been received




Start Initialize Spring Project Application

I will build spring boot project from scratch. And I will categorize with 3 module : First module is parent pom module as wrapper project, second is the sender module for sender service to send message to rabbitmq broker and the last one is the receiver module for receiver queue message from rabbitmq broker. 


Watch Full Video Tutorial: 




{getCard} $type={post}

Previous Post Next Post