Skip to content

a lightweight RabbitMQ wrapper built with `amqplib`, designed for seamless message sending and receiving with minimal setup. Perfect for quick integrations and scalable solutions.

Notifications You must be signed in to change notification settings

marcuwynu23/frbjs

Repository files navigation

FireRabbit.js

Stars Badge Forks Badge Issues Badge License Badge

FireRabbit is a simple, lightweight wrapper for RabbitMQ using the amqplib library. It simplifies sending and receiving messages with minimal configuration, making it ideal for quick integrations and scalable messaging solutions.

Installation

Install FireRabbit via npm:

npm install @marcuwynu23/frbjs

Features

  • Easy connection initialization with RabbitMQ.
  • Simple methods to send and receive messages.
  • Handles JSON messages seamlessly.
  • Graceful connection and channel closure.

Usage

Initialize FireRabbit

Create a new instance of the FireRabbit class and initialize the RabbitMQ connection.

const FireRabbit = require('@marcuwynu23/frbjs');

(async () => {
  const rabbit = new FireRabbit();
  await rabbit.init('amqp://localhost');
})();

Send a Message

Send a message to a specified RabbitMQ queue.

const FireRabbit = require('@marcuwynu23/frbjs');

(async () => {
  const rabbit = new FireRabbit();
  await rabbit.init('amqp://localhost');

  const queueName = 'test-queue';
  const message = { id: 1, text: 'Hello, RabbitMQ!' };

  await rabbit.send(queueName, message);
  await rabbit.close();
})();

Receive Messages

Listen to a RabbitMQ queue and process incoming messages.

const FireRabbit = require('@marcuwynu23/frbjs');

(async () => {
  const rabbit = new FireRabbit();
  await rabbit.init('amqp://localhost');

  const queueName = 'test-queue';

  const message = await rabbit.receive(queueName);
	console.log("Received message:", message);
})();

Close the Connection

Close the RabbitMQ connection gracefully:

await rabbit.close();

Environment Variables

You can use environment variables to configure the RabbitMQ URI:

  • RABBIT_MQ_URI: The URI for the RabbitMQ server (e.g., amqp://localhost).

Error Handling

Ensure you handle errors properly, especially when initializing the connection or interacting with RabbitMQ. For example:

try {
  await rabbit.init('amqp://localhost');
} catch (error) {
  console.error('Failed to initialize RabbitMQ:', error);
}

License

FireRabbit is open-source software licensed under the MIT License.


Happy messaging with FireRabbit!

About

a lightweight RabbitMQ wrapper built with `amqplib`, designed for seamless message sending and receiving with minimal setup. Perfect for quick integrations and scalable solutions.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published