Messaging queue with RabbitMQ! ✉️

Messaging queue with RabbitMQ! ✉️

How to create a dotnet core template to be used via the command line or visual studio.

A long time ago, at my college, I gave a presentation, the topic was free and I could choose a technology that was trending to talk about, at the time the technology chosen was about messaging, I was starting to study microservices architecture and I I came across this incredible topic, recently github started to alert me about some vulnerabilities that appeared in the project (developed in NodeJS), so I decided to take the opportunity to update and write a little about it.

But before starting, I would like to talk about why they emerged and what is the use of messaging, in distributed and large-scale systems, one of the problems that needs to be solved is communication, before messaging, both http and tcp already existed. , however there is a problem that these protocols do not solve, which is the guarantee of delivery, you can send data to another system, but if you need to guarantee that the message is received you need to develop the retry, timeout, semaphore logic yourself, among others .

Furthermore, if you need to send the same event to several services or if you use a Kubernetes infrastructure, for example, that allows nodes to be taken down, new ones added and scaled up easily, knowing where to send this message can become very complex.

To solve these problems, it is possible to use messaging services, with which you can customize according to your use, and among them, RabbitMQ is very flexible and easy to configure.

First let’s talk about how to upload a local instance of RabbitMQ (on your machine), this makes development a lot easier as it will be our laboratory for testing, and a tool that helps a lot with this is Docker, there are several tutorials for installing Docker, it is totally Compatible with Windows, Mac or Linux 🐧. Once installed, you can upload RabbitMQ with a AMAZING single command!

docker run --rm -it --hostname my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

In it we are basically saying that:

  • If there is already a Docker with Rabbit running, delete it and upload it again,
  • Defines the version and ports that need to be opened
  • Attaches the terminal to this instance, to see the creation status and monitor what happens in real time.

Now comes the interesting part in my opinion of the presentation, cloning the repository: queue-exemples and running the following commands:

npm install
npm start

Let’s start the application on port 8080, in which I created a simple html that was used for other students to access and evaluate the presentation, but so far, nothing much, right? The difference is that, the server that will process this request is initially turned off, so all the evaluations given by other students are sent but until then they are not delivered anywhere, after everyone evaluates, all we need to do is upload the server that it’s inside the folder /app from the same repository by running the command node queue-server.js and yes, the entire server is written in one file, NodeJS can be very impressive…

Queue Server