npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

uor-rabbit

v1.0.0

Published

RabbitMQ utility library for UOR Budget applications

Readme

UOR Rabbit

A reusable RabbitMQ utility library for UOR Budget applications that provides both producer and consumer functionality.

Features

  • Simple, configurable RabbitMQ connection management
  • Message producer for sending messages to queues
  • Message consumer for receiving and processing messages
  • Automatic reconnection handling
  • Event-based communication
  • Flexible message format support
  • Error handling and logging

Installation

npm install uor-rabbit

Usage

Producer Example

const { RabbitProducer } = require('uor-rabbit');

// Initialize producer with custom options
const producer = new RabbitProducer({
  url: process.env.RABBITMQ_URL || 'amqp://localhost',
  queueName: process.env.RABBITMQ_QUEUE || 'telegram_notifications',
  logger: console // or your custom logger
});

// Connect to RabbitMQ
await producer.initialize();

// Send a message
await producer.sendMessage({
  receivers: ['123456789'],
  body: 'Hello from UOR Budget!',
  data: { timestamp: new Date().toISOString() }
});

// Or send to multiple receivers
await producer.sendMessage({
  receivers: ['123456789', '987654321'],
  body: 'Broadcast message',
  data: { type: 'notification' }
});

// Listen for events
producer.on('messageSent', (message) => {
  console.log('Message sent successfully:', message);
});

producer.on('error', (error) => {
  console.error('RabbitMQ error:', error.message);
});

// Close connection when done
await producer.close();

Consumer Example

const { RabbitConsumer } = require('uor-rabbit');

// Initialize consumer with custom options
const consumer = new RabbitConsumer({
  url: process.env.RABBITMQ_URL || 'amqp://localhost',
  queueName: process.env.RABBITMQ_QUEUE || 'telegram_notifications',
  logger: console // or your custom logger
});

// Connect to RabbitMQ
await consumer.initialize();

// Register message handler
consumer.onMessage(async (receivers, body, data) => {
  console.log(`Processing message for ${receivers.length} receivers`);
  
  for (const userId of receivers) {
    // Process each receiver
    console.log(`Sending message to user ${userId}: ${body}`);
  }
});

// Start consuming messages
await consumer.startConsuming();

// Listen for events
consumer.on('message', (message) => {
  console.log('Received message:', message);
});

consumer.on('error', (error) => {
  console.error('RabbitMQ error:', error.message);
});

// Close connection when done
await consumer.close();

Configuration Options

Both RabbitProducer and RabbitConsumer accept the following options:

| Option | Description | Default | |--------|-------------|---------| | url | RabbitMQ connection URL | process.env.RABBITMQ_URL or 'amqp://localhost' | | queueName | Queue name | process.env.RABBITMQ_QUEUE or 'telegram_notifications' | | queueOptions | Queue options | { durable: true } | | reconnectInterval | Reconnect interval in ms | 5000 | | maxReconnectAttempts | Maximum reconnect attempts | 3 | | logger | Logger instance | console | | messageOptions | Message options (Producer only) | { persistent: true } | | consumeOptions | Consume options (Consumer only) | {} |

Message Format

The library supports the following message format:

{
  "receivers": ["123456789", "987654321"],
  "body": "Your notification message",
  "data": { "key": "value" }
}

The receivers field must be a non-empty array of receiver IDs.

Events

Common Events

  • connected: Emitted when connected to RabbitMQ
  • error: Emitted on general errors
  • connectionError: Emitted on connection errors
  • connectionClosed: Emitted when connection is closed unexpectedly
  • reconnected: Emitted when successfully reconnected
  • reconnectError: Emitted when reconnection fails
  • maxReconnectAttemptsReached: Emitted when maximum reconnect attempts are reached
  • closed: Emitted when connection is closed
  • closeError: Emitted when there's an error closing the connection

Producer Events

  • messageSent: Emitted when a message is sent successfully
  • sendError: Emitted when there's an error sending a message

Consumer Events

  • consumingStarted: Emitted when consuming starts
  • consumeError: Emitted when there's an error starting to consume
  • message: Emitted when a message is received and validated
  • messageError: Emitted when there's an error processing a message
  • invalidMessage: Emitted when a message is invalid

License

AGPL-3.0