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 🙏

© 2024 – Pkg Stats / Ryan Hefner

rabbitmq-controller

v2.1.0

Published

The RabbitMQController is a TypeScript Library that provides a convenient way to manage RabbitMQ connections for Nodejs with features like automatic reconnection and error handling. It extends the `EventEmitter` class to emit events for various connection

Downloads

18

Readme

Getting the RabbitMQ Instance

You can obtain the underlying RabbitMQ instance from the rabbitmq-controller package. Here's how to do it:

First, import the Manager class from the package into your application:

import { Manager } from "rabbitmq-controller";

Next, create an instance of the Manager by providing the RabbitMQ server URL and optional configuration parameters. You can also set the maximum number of retry attempts and the reconnection timeout.

const rabbitMQController = new Manager(
  "amqp://localhost", // RabbitMQ server URL
  5, // Maximum retry attempts (optional)
  5000 // Reconnection timeout in milliseconds (optional)
);

To start the RabbitMQ connection, use the start method as described in the previous section:

rabbitMQController
  .start()
  .then(() => {
    console.log("Connected to RabbitMQ server.");
  })
  .catch((error) => {
    console.error("Error connecting to RabbitMQ server:", error);
  });

Once you have started the connection, you can access the RabbitMQ instance by using the client property of the rabbitMQController object. This property provides direct access to the RabbitMQ instance created by the amqplib library:

const rabbitmqConnection = rabbitMQController.client;

// Now you can use 'rabbitmqConnection' to work with the RabbitMQ instance directly.
// For example, you can create channels, publish messages, and subscribe to queues using the 'amqplib' methods.

This allows you to interact with the RabbitMQ instance using the full set of methods provided by the amqplib library.

Events

The RabbitMQManager emits events to notify you of various connection states and errors. You can listen to these events to handle specific scenarios in your application.

  • open: Emitted when the connection to the RabbitMQ server is established.
  • closed: Emitted when the connection is closed, and the controller is attempting to reconnect.
  • reconnecting: Emitted when the controller is in the process of reconnecting.
  • connecting: Emitted when the controller is attempting to connect to the RabbitMQ server.
  • error: Emitted when an error occurs during the connection process.

You can use the on method to listen to these events and respond to them in your code:

rabbitMQController.on("open", (manager) => {
  console.log("RabbitMQ connection is open.");
});

rabbitMQController.on("connecting", (manager) => {
  console.log("RabbitMQ connection is in the process of connecting.");
});

rabbitMQController.on("error", (manager, error) => {
  console.error("RabbitMQ error:", error);
});

Management Api

The RabbitMQController offers some mods that not in amqplib such as getting all the client data. so in this manager it has built in functions to get that data.

const rabbitMQMangement = new ManagementApi({
  url: "http://localhost:15672", // Rabbitmq Management url
  username: "guest", // Rabbitmq Management username
  password: "guest", // Rabbitmq Management password
});

License

This package is released under the MIT License. See the LICENSE file for details.