Skip to content

Latest commit

 

History

History
15 lines (15 loc) · 1.37 KB

File metadata and controls

15 lines (15 loc) · 1.37 KB

License: MIT Javascript

Implementing Rabbitmq with Nodejs

RabbitMq is a messaging broker or queue manager which uses AMQP(Advanced Message Queuing Protocol) to transfer messages between various services.

A message broker acts as a middleman for various services (e.g. a web application, as in this example). They can be used to reduce loads and delivery times of web application servers by delegating tasks that would normally take up a lot of time or resources to a third party that has no other job.

Implementation


  • Here I have implemented two simple services in Nodejs where RabbitMq acts as a message broker between the two.
  • The first service /service1 is used to push a new record with name and email to a database. Here we record the autogenerated id from the response and send it to a message queue.
  • The second service /service2 consumes the messages from the message queue and prints the data it received on the console.
  • The data stored in the message queues is persistent which means even if one service goes down the data in the queue will be retained until the service is up again and acknowledges the messages it consumed.