aob-rabbit-wrapper

Node.js wrapper for rabbit methods

Usage no npm install needed!

<script type="module">
  import aobRabbitWrapper from 'https://cdn.skypack.dev/aob-rabbit-wrapper';
</script>

README

Usage

$ import { createRabbitConnectionToPublish } from 'aob-rabbit-wrapper'
$ import { createRabbitConnectionToSubscribe } from 'aob-rabbit-wrapper'

This package exposes following methods | Method | Description | Params | ------ | ------ | ------ | | createRabbitConnectionToPublish | Create connection and bind it with exchange provide | {publishConnectionMap} | createRabbitConnectionToSubscribe | Create connection for subscribing the queues binded with multiple exchanges in rabbit Mq | {publishConnectionMap}

createRabbitConnectionToPublish

Give Options of rabbit and event publisher list for setting up the connection. It will map a callback came from rabbitMq when connection established. Which is mapped in publishConnectionMap.

publishConnectionMap in this map you'll get the publisher callback on which you can publish messgae using the exchange name and routing key For example:

  • Options
const rabbitOptions = () => ({
    host: localhost,
    port: 5672,
    login: rabbitLoginUserName,
    password: rabbitLoginUserPassword,
    connectionTimeout: 10000,
    authMechanism: 'AMQPLAIN',
    vhost: '/',
    noDelay: true,
    ssl: { enabled: false },
  });
  • PublisherList
 eventPublisherList: 
 [ { routingKey: rabbitRoutingKey,
     exchangeName: exchangeNameForPublishingEvent,
     exchangeType: 'topic', // direct, fanout, headers
     eventId: 1 },
   { routingKey: 'rabbitRoutingKey',
     exchangeName: 'exchangeNameForPublishingEvent',
     exchangeType: 'fanout',
     eventId: 2 } ],

createRabbitConnectionToSubscribe

Give subsciber list for setting up the connection to the rabbitMQ. Pass the function reference with the subscriber list which will receive the msg on referenced function.

For example:

  • Subscriber List
eventSubscriberList: 
 [ { routingKey: 'rabbitRoutingKey',
     exchangeName: 'exchangeNameForSubscribing',
     queueName: 'queueName',
     exchangeType: 'topic' },
   { routingKey: 'rabbitRoutingKey',
     exchangeName: 'exchangeNameForSubscribing',
     queueName: 'queueName',
     exchangeType: 'fanout' } ] }