npm.io
1.0.5 • Published 8 years ago

aob-rabbit-wrapper

Licence
ISC
Version
1.0.5
Deps
3
Size
18 kB
Vulns
0
Weekly
0

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' } ] }