Skip to content

itavy/mq-router

Repository files navigation

MQ-Router

Instalation

npm install @itavy/mq-router

API

Classes

MQRouter

Class MQRouter

RequestsRoutingTable

MQRequestsRoutingTable class

Objects

itavy/mq-router : object

MQRouter module

Typedefs

MQPublishOptions : Object

MQRouter

Class MQRouter

Kind: global class

new MQRouter(mqURI, [connector], mqMessage, mqKnownMessages, mqDefaultMessageVersion, name, [queue], [topic], [exchange], [errorCollector], [defaultHandler], [defaultTTL])

Param Type Default Description
mqURI String uri for connecting to mq bus
[connector] String RABBIT_MQ connector type to use
mqMessage Object message builder
mqKnownMessages Array.<Object> list of known message versions
mqDefaultMessageVersion Object default version of message to use
name String router identifier
[queue] String '' own queue on which the router will listen
[topic] String '' own topic on which the router will listen
[exchange] String '' exchange to bind the topic
[errorCollector] function function to be called when unknown messages are received
[defaultHandler] function function which resolves to a promise to be called when it receives specific messages
[defaultTTL] Number 5 default ttl in seconds for messages or requests sent

mqRouter.sendMessage(message, version, queue, exchange, [options]) ⇒ Promise

Send message over mq

Kind: instance method of MQRouter
Returns: Promise - resolves when the message is accepted by the broker
Access: public

Param Type Default Description
message Buffer message to be sent
version Object version of message to be sent
queue String queue or topic where to send the message
exchange String exchange to be used along with queue/topic to send the message, empty string means the default exchange will be used
[options] MQPublishOptions {} options for sending message

mqRouter.sendRequest(message, queue, exchange, [options], version) ⇒ Promise

Send request over mq

Kind: instance method of MQRouter
Returns: Promise - resolves when the message is received
Access: public

Param Type Default Description
message Buffer message to be sent
queue String queue or topic where to send the message
exchange String exchange to be used along with queue/topic to send the message, empty string means the default exchange will be used
[options] MQPublishOptions {} options for sending request
version Object version of message to be sent

mqRouter.subscribe(handler, [queue], [topic], [exchange], [options]) ⇒ Promise

Subscribe to queue

Kind: instance method of MQRouter
Returns: Promise - resolves on success subscribe
Access: public

Param Type Default Description
handler Promise Promise to be called when it is received a message
[queue] String '' queue where to subscribe or '' for autogenerated queue
[topic] String '' topic to bind the queue or '' for none
[exchange] String '' exchange to be used for queue and topic or '' for default
[options] Object {} subscribe options

mqRouter.close() ⇒ Promise

Close stops checks for expired messages and close connection

Kind: instance method of MQRouter
Returns: Promise - resolves when connection is closed
Access: public

RequestsRoutingTable

MQRequestsRoutingTable class

Kind: global class

new RequestsRoutingTable(name, [checkInterval])

Param Type Default Description
name String router name
[checkInterval] Number 200 check interval in ms to see if requests have passed their ttl

requestsRoutingTable.register(serializedMessage, id, options) ⇒ Promise

Register a check for a request

Kind: instance method of RequestsRoutingTable
Returns: Promise - resolves with promise that will be resolved upon receiving message
Access: public

Param Type Description
serializedMessage Buffer message to be sent
id String message id
options Object message options

requestsRoutingTable.callById(id, [message], [error]) ⇒ Boolean

Resolve a request

Kind: instance method of RequestsRoutingTable
Returns: Boolean - true if listener exists
Throws:

  • IError if listener does not exists

Access: public

Param Type Default Description
id String message id
[message] Buffer response message
[error] Object error to be sent to handler

requestsRoutingTable.setMessagesTimeoutListener(emitter) ⇒ undefined

Setter for event emitter

Kind: instance method of RequestsRoutingTable
Access: public

Param Type Description
emitter EventEmitter event emitter

requestsRoutingTable.close() ⇒ undefined

Stops checks for expired messages

Kind: instance method of RequestsRoutingTable
Access: public

itavy/mq-router : object

MQRouter module

Kind: global namespace

MQPublishOptions : Object

Kind: global typedef
Properties

Name Type Description
ttl Number ttl in seconds for the message

TODO

  • more examples and better documentation
  • more e2e testing
  • refactor tests for nodejs 6

LICENSE

MIT