Skip to main content

Command Palette

Search for a command to run...

Rabbit MQ

Published
2 min read
M

As a former 3D Animator with more than 12 years of experience, I have always been fascinated by the intersection of technology and creativity. That's why I recently shifted my career towards MERN stack development and software engineering, where I have been serving since 2021.

With my background in 3D animation, I bring a unique perspective to software development, combining creativity and technical expertise to build innovative and visually engaging applications. I have a passion for learning and staying up-to-date with the latest technologies and best practices, and I enjoy collaborating with cross-functional teams to solve complex problems and create seamless user experiences.

In my current role as a MERN stack developer, I have been responsible for developing and implementing web applications using MongoDB, Express, React, and Node.js. I have also gained experience in Agile development methodologies, version control with Git, and cloud-based deployment using platforms like Heroku and AWS.

I am committed to delivering high-quality work that meets the needs of both clients and end-users, and I am always seeking new challenges and opportunities to grow both personally and professionally.

RabbitMQ Documentation

RabbitMQ is an open-source message broker that enables applications to communicate with each other through messaging queues.

Key Features

  • Reliability: Messages are acknowledged, ensuring they are processed reliably.

  • Flexibility: Supports multiple messaging protocols such as AMQP, MQTT, and STOMP.

  • Scalability: Can be clustered to handle large amounts of data.

  • Management UI: Provides a web-based UI to manage and monitor RabbitMQ.

  • High Availability: Ensures message queues are replicated across multiple nodes.

Core Concepts

  1. Producer: Sends messages to RabbitMQ.

  2. Consumer: Receives messages from RabbitMQ.

  3. Queue: Stores messages until they are consumed.

  4. Exchange: Routes messages to queues based on routing keys.

  5. Binding: Defines the relationship between exchanges and queues.

  6. Routing Key: Used to determine how messages are routed to queues.

Example Usage

Producer Example

Copy

javascriptCopy codeconst amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', (err, connection) => {
  if (err) throw err;
  connection.createChannel((err, channel) => {
    if (err) throw err;
    const queue = 'hello';
    const msg = 'Hello World';

    channel.assertQueue(queue, { durable: false });
    channel.sendToQueue(queue, Buffer.from(msg));
    console.log(`[x] Sent ${msg}`);
  });

  setTimeout(() => {
    connection.close();
    process.exit(0);
  }, 500);
});

Consumer Example

Copy

javascriptCopy codeconst amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', (err, connection) => {
  if (err) throw err;
  connection.createChannel((err, channel) => {
    if (err) throw err;
    const queue = 'hello';

    channel.assertQueue(queue, { durable: false });
    console.log(`[*] Waiting for messages in ${queue}. To exit press CTRL+C`);

    channel.consume(queue, (msg) => {
      console.log(`[x] Received ${msg.content.toString()}`);
    }, { noAck: true });
  });
});

Benefits

  1. Reliability: Ensures messages are delivered and processed reliably.

  2. Flexibility: Supports various messaging patterns and protocols.

  3. Ease of Use: Simple setup and easy integration with different programming languages.

  4. Scalability: Can handle increased load by adding more nodes.

  5. Management Tools: Provides a robust UI for managing and monitoring.

Use Cases

  • Task Queues

  • Asynchronous Processing

  • Microservices Communication

  • Event Distribution

  • Real-time Messaging