Skip to content

hardikshakya/rabbitmq-nodejs-demos

Repository files navigation

RabbitMQ Demos/Tutorials Using NodeJS

This repository contains RabbitMQ Demos/Tutorials with amqplib node-js library.

RabbitMQ speaks multiple protocols. But in this demo/tutorial I used AMQP 0-9-1, which is an open, general-purpose protocol for messaging.

Requirements

Getting Started

  • Wants to run my demo code:

    • Clone the repository:

      git clone <Repository Path>
      cd rabbitmq-nodejs-demos
    • Install all dependencies:

      npm install
  • Wants to run your own code:

    npm init -y
    npm install amqplib

Running Locally

  • In terminal 1 start/run rabbitmq server with docker:

    docker-compose up --build
  • In terminal 2 start message/job publisher:

    node <folder-name>/producer.js
  • In terminal 3 start message/job consumer:

    node <folder-name>/consumer.js

Demos

A "Simple Hello World" example, with one script producer.js sending a message to a queue,and another consumer.js receiving messages from the same queue.

Using RabbitMQ as a work queue; producer.js creates a task, and consumer.js processes tasks. Multiple consumer.js process will share the tasks among them. Long-running tasks are simulated by supplying a delay time(second) in command arguments.

Using RabbitMQ as a broadcast mechanism. producer.js sends a "log" message to a fanout exchange, and all consumer.js processes receive log messages.

Using RabbitMQ as a routing ('somecast') mechanism. producer.js sends a log message with a severity/routing key, and all consumer.js processes receive log messages for the severities/binding keys on which they are listening.

With help of topic we can able to overcome the limitation of previous feature/demo routing. Here we can pass complex wildcard pattern.

Using RabbitMQ as an RPC(Remote procedure call) intermediary, queueing requests for servers and routing replies back to clients.

Using RabbitMQ as a priority queue, showing how to set maximum priority value supported by the queue and setting priority of each message pushed to the queue. In case of messages having equal value of priority, they are consumed in FIFO order.

The RabbitMQ Delayed Message Plugin adds a new exchange type to RabbitMQ where messages routed by that exchange can be delayed if the user adds a delay header to a message.

Using RabbitMQ to implement a basic multiple retry mechanism in case of processing failures in message/job consumer.

About

RabbitMQ Demos/Tutorials with AMQP protocol. [NodeJS]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published