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

@hirehq/queue-service

v1.0.0

Published

HireHQ Queue Service - Private package for queue subscriber and publisher functionality

Readme

@hirehq/queue-service

A private npm package for HireHQ queue subscriber and publisher functionality using RabbitMQ.

Features

  • Queue Subscriber: Consume messages from RabbitMQ queues
  • Queue Publisher: Publish messages to RabbitMQ exchanges
  • Unified Queue Service: Combined subscriber and publisher functionality
  • TypeScript Support: Full TypeScript definitions included
  • Configurable: Environment-based configuration with fallbacks
  • Error Handling: Robust error handling and logging

Installation

npm install @hirehq/queue-service

Usage

Basic Usage

import { createQueueService, MessageHandler } from '@hirehq/queue-service';
import { ConsumeMessage } from 'amqplib';

// Define your message handler
class MyMessageHandler implements MessageHandler {
  async handleMessage(msg: ConsumeMessage): Promise<void> {
    const messageContent = msg.content.toString();
    console.log('Received message:', messageContent);

    // Process your message here
    const data = JSON.parse(messageContent);
    // ... your processing logic
  }
}

// Create queue service
const messageHandler = new MyMessageHandler();
const queueService = createQueueService(fastifyInstance, messageHandler);

// Start subscription
await queueService.startSubscription();

// Publish a message
const success = await queueService.publishMessage({
  type: 'notification',
  data: { userId: '123', message: 'Hello!' }
});

// Publish with custom routing key
const success = await queueService.publishMessage(
  { type: 'email', data: { to: '[email protected]' } },
  'email.notification'
);

Advanced Usage

import { QueueService, QueueConfig } from '@hirehq/queue-service';

// Custom configuration
const config: QueueConfig = {
  queueName: 'my-custom-queue',
  exchangeName: 'my-custom-exchange',
  routingKey: 'my-custom-routing-key',
  host: 'rabbitmq.example.com',
  port: 5672,
  username: 'myuser',
  password: 'mypassword',
  vhost: '/myvhost'
};

// Create with custom config
const queueService = new QueueService(fastifyInstance, messageHandler);

// Publish batch messages
const messages = [
  { type: 'email', data: { to: '[email protected]' } },
  { type: 'sms', data: { to: '+1234567890' } },
  { type: 'notification', data: { userId: '123' } }
];

const result = await queueService.publishBatch(messages, 'batch.notification');
console.log(`Published: ${result.success} successful, ${result.failed} failed`);

// Check subscription status
if (queueService.isSubscriptionActive()) {
  console.log('Queue subscription is active');
}

// Close connection
await queueService.closeConnection();

Environment Variables

The package uses the following environment variables with defaults:

  • RABBITMQ_QUEUE_NAME (default: 'notification_queue')
  • RABBITMQ_EXCHANGE_NAME (default: 'notification_exchange')
  • RABBITMQ_ROUTING_KEY (default: 'notification')
  • RABBITMQ_HOST (default: 'localhost')
  • RABBITMQ_PORT (default: 5672)
  • RABBITMQ_USERNAME (default: 'guest')
  • RABBITMQ_PASSWORD (default: 'guest')
  • RABBITMQ_VHOST (default: '/')

API Reference

QueueService

Main class that combines subscriber and publisher functionality.

Methods

  • startSubscription(): Start consuming messages from the queue
  • publishMessage(message, routingKey?): Publish a single message
  • publishMessageWithOptions(options): Publish with advanced options
  • publishBatch(messages, routingKey?): Publish multiple messages
  • closeConnection(): Close the queue connection
  • isSubscriptionActive(): Check if subscription is active

QueueSubscriber

Handles message consumption from RabbitMQ queues.

Methods

  • startSubscription(): Start the subscription
  • stopSubscription(): Stop the subscription
  • isSubscriptionActive(): Check subscription status

QueuePublisher

Handles message publishing to RabbitMQ exchanges.

Methods

  • publishMessage(message, routingKey?): Publish a single message
  • publishMessageWithOptions(options): Publish with options
  • publishBatch(messages, routingKey?): Publish multiple messages

Types

QueueConfig

interface QueueConfig {
  queueName?: string;
  exchangeName?: string;
  routingKey?: string;
  host?: string;
  port?: number;
  username?: string;
  password?: string;
  vhost?: string;
}

MessageHandler

interface MessageHandler {
  handleMessage(msg: ConsumeMessage): Promise<void>;
}

PublishMessageOptions

interface PublishMessageOptions {
  message: any;
  routingKey?: string;
  exchangeName?: string;
  persistent?: boolean;
}

Development

Building

npm run build

Testing

npm test

Linting

npm run lint
npm run lint:check

Formatting

npm run format
npm run format:check

License

UNLICENSED - Private package for HireHQ use only.