1.1.7 • Published 10 months ago

@marcuwynu23/frbjs v1.1.7

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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!

1.1.7

10 months ago

1.1.6

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago