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 🙏

© 2026 – Pkg Stats / Ryan Hefner

simple-rabbitmq-connection

v0.0.1

Published

Simple rabbitmq connection

Downloads

2

Readme

simple-rabbitmq-connection - Simple rabbitmq connection

Conexión a rabbit

La libreria se encargara de inicializar los canales, crear las queues y los bindeos correspondientes mediante el metodo "init()". Para los casos de consumers, debe haber un objeto de configuracion llamado "consumer", la queue manual se generara de forma automatica la cual se encargara de desechar los mensajes que fallen antes del ack segun la politica de reintentos seteada (con posibilidad de sobreescrirla).

Enviar un mensaje

rabbitSendEvent

rabbitSendEvent(message, queueName, channelName, options)

rabbitPublishEvent

rabbitPublishEvent(exchangeName, channelName, routingKey, message, options)

Configuraciones

Conexion

  connectionObject: {
    user: 'guest',
    pass: 'guest',
    server: '127.0.0.1',
    port: '5672',
    vhost: '/',
    protocol: 'amqp'
  },

Consumer (nombre del objeto 'consumer' es obligatorio)

  consumer: {
    id: 'consumerChannel',
    queues: [
      {
        id: 'consumerChannel',
        type: 'fanout',
        name: 'queue_consumer',
        json: true,
        retry: 2,
        retry_timeout: 5000
      },
    ],
  },
      

Politica de reintentos consumer:

La propiedad "retry" del consumer debe ser un numero. En caso que no se requiera una politica de reintento setearla en 0. Para los casos que se quiere reintentar de forma indefinida setearla en -1

Queues y exchanges (puede ser un array de queues y pueden o no tener mas informacion, por ejemplo bindingKey). No es obligatorio tener un exchange declarado

  exampleQueue: {
    id: 'example_channel',
    queues: [
      {
        name: 'queue_test',
        bindingKey: 'bindingKeyExample'
      },
    ],
    exchange: {
      channelId: 'example_channel',
      name: 'exchange_example',
      type: 'x-delayed-message',
      options: {
        autoDelete: false,
        durable: true,
        passive: true,
        arguments: { 'x-delayed-type': 'direct' }
      }
    }
  },
      

Nota al poner un bind entre un exchange y una o varias queues:

La property "channelId" exchange debe coincidir con la property id del objeto que la contiene. En el ejemplo anterior seria "example_channel".

Ejemplo config completo

  conexionObject: {
    user: 'guest',
    pass: 'guest',
    server: '127.0.0.1',
    port: '5672',
    vhost: '/',
    protocol: 'amqp'
  },
  config: {
    consumer: {
      id: 'consumerChannel',
      queues: [
        {
          id: 'consumerChannel',
          type: 'fanout',
          name: 'queue_consumer',
          json: true,
          retry: 2,
          retry_timeout: 5000
        },
      ],
    },
    exampleQueue: {
      id: 'example_channel',
      queues: [
        {
          name: 'queue_test',
          bindingKey: 'bindingKeyExample'
        },
      ],
      exchange: {
        channelId: 'example_channel',
        name: 'exchange_example',
        type: 'x-delayed-message',
        options: {
          autoDelete: false,
          durable: true,
          passive: true,
          arguments: { 'x-delayed-type': 'direct' }
        }
      }
    },
    anotherExampleQueue: {
      id: 'another_example_channel',
      queues: [
        {
          name:  'queue_test_2'
        },
      ],
      exchange: {
        channelId: 'another_example_channel',
        name: 'another_exchange_example',
        type: 'fanout'
      }
    },
  }

Inicializar rabbit:

const src = require('simple-rabbitmq-conection');

const rabbitInstance = async () => {
  const rabbit = new src.RabbitmqConnection(
    config.conexionObject, // objeto de conexion
    config.config // objeto de configuracion
  );
  await rabbit.init(); 

  // caso de que se utilice un consumer, indicar quien recibe el mensaje
  await rabbit.setupQueuesConsumer(
    middleware.initialMiddleware
  );

  return rabbit;
}

- Ejemplo implementar mensaje:

const anotherExample = congig.anotherExampleQueue;

const sendMessage = function () {
  this.send = async (data, headers) => {
    try {
      const sender = await rabbitInstance(); // aqui deberia llamar a donde haya declrado la funcion init()
      const response = await sender.rabbitPublishEvent(
        anotherExample.exchanges[0].name,
        anotherExample.id,
        '',
        data,
        { headers }
      );
      return response;
    } catch (e) {
      throw e;
    }
  };
};

Credits

By Paulo Ariel Pareja