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