0.1.44 • Published 6 years ago

rabbitmq-tools v0.1.44

Weekly downloads
3
License
Apache License 2....
Repository
github
Last release
6 years ago

Rabbit-tools

This library is aimed to ease amqplib usage.

Commitizen friendly

Installation:

npm i rabbitmq-tools -S

Following features are implemented:

  • Client reconnection
  • Failed channel reopening
  • Routing and message validation via jsonschema
  • Promise based querying interface that is curried by default

Usage

The library allow you to easily handle amqp routing and request/publish routines. The simpliest usage is:

const client = ReactiveMQ.create({
  url,
  appId,
  routerConfig: {
    routes: [
      {
        exchange: 'amq.topic',
        routingKey: 'hardware.v1.created',
        resolver: () => {}
      }
    ]
  }
})

client.publish('amq.topic', 'routing.key', { foo: 'bar' })
client.request('amq.topic', 'routing.key', { foo: 'bar' })
  .then(response => {})

Reference

RxConnection

connect(url, options)

returns Rx.BehaviorSubject instance emitting amqp.connection or null in case of no connection/connection close

Params

url (string | object): amqp url string or object, same as described in amqplib

options.logger ({ log, warn } | null | false): logger to output connection state changes. Default is console. Set falsy value to disable logging

import { connect } from 'rabgbitmq-tools'

const rxConnection = connect(url, options)

RxChannel

openChannel(rxConnection, options)

returns Rx.BehaviorSubject instance emitting amqp.channel or null in case of no connection/connection close

Params

rxConnection (Rx.BehaviorSubject): Rx.BehaviorSubject instance emitting amqp.connection or null in case of no connection/connection close

options.logger ({ log, warn } | null | false): logger to output connection state changes. Default is console. Set falsy value to disable logging

import { openChannel } from 'rabgbitmq-tools'

const rxChannel = openChannel(rxConnection, options)

class ReactiveMQ

constructor(options)

Constructor params

options.url (string | object): amqp url string or object, same as described in amqplib

options.appId (string): application identifier used in publishing/request logic. read more...

options.connectionId (string): application identifier used as a prefix in logging. Consists of logging scope and vhost if available

options.logger ({ log, warn } | null | false): logger to output connection state changes. Default is console. Set falsy value to disable logging

options.routerConfig ({ routes: object }): see Router doc below

const client = ReactiveMQ.create({
  url: 'rabbitMQUrl',
  appId: 'appId'
})

Instance methods

publish(exchange, routingKey, message)

returns Promise

exchange (string): amqp exchange routingKey (string): amqp routingKey to publish to message (any): data to buplish

method is curried by default

request(exchange, replyTo, routingKey, message)

returns Promise

exchange (string): amqp exchange replyTo (string): queue to receive a reply routingKey (string): amqp routingKey to publish to message (any): data to buplish

method is curried by default

connectRouter(routerConfig)

returns void

options.routerConfig ({ routes: object }): see Router doc below

This is useful if you need to provide routes after client initialization. Starts up router and does all the logic related to listening to events.

class Router

constructor(options)

Constructor params

options.appId (string): application identifier used in publishing/request logic. read more...

options.connectionId (string): application identifier used as a prefix in logging. Consists of logging scope and vhost if available

options.logger ({ log, warn } | null | false): logger to output connection state changes. Default is console. Set falsy value to disable logging

options.routes (object): actual router config representing queue and consumer options, validation and handling

options.routes.exchange (string): exchange to bind queue to

options.routes.routingKey (string): routingKey to bind queue to

options.routes.resolver (function): event handler that is passed a message payload and expected to return any output that may be received by initial emitter

options.routes.requestSchema (json): json schema object to validate a message. read more...

options.routes.queueOptions (object): options passed to channel.bindQueue. read more...

options.routes.consumerOptions (object): options passed to channel.consume. read more...

Roadmap

  • Implement more flexible amqp configurations
  • Cover with tests
  • Improve documentation
0.1.44

6 years ago

0.1.43

6 years ago

0.1.42

6 years ago

0.1.41

6 years ago

0.1.40

6 years ago

0.1.39

6 years ago

0.1.38

6 years ago

0.1.37

6 years ago

0.1.36

6 years ago

0.1.35

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago