1.0.0 • Published 5 years ago

@itavy/mq-router v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

MQ-Router

Instalation

npm install @itavy/mq-router

API

Classes

Objects

Typedefs

MQRouter

Class MQRouter

Kind: global class

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

ParamTypeDefaultDescription
mqURIStringuri for connecting to mq bus
connectorStringRABBIT_MQconnector type to use
mqMessageObjectmessage builder
mqKnownMessagesArray.<Object>list of known message versions
mqDefaultMessageVersionObjectdefault version of message to use
nameStringrouter identifier
queueString''own queue on which the router will listen
topicString''own topic on which the router will listen
exchangeString''exchange to bind the topic
errorCollectorfunctionfunction to be called when unknown messages are received
defaultHandlerfunctionfunction which resolves to a promise to be called when it receives specific messages
defaultTTLNumber5default 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

ParamTypeDefaultDescription
messageBuffermessage to be sent
versionObjectversion of message to be sent
queueStringqueue or topic where to send the message
exchangeStringexchange to be used along with queue/topic to send the message, empty string means the default exchange will be used
optionsMQPublishOptions{}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

ParamTypeDefaultDescription
messageBuffermessage to be sent
queueStringqueue or topic where to send the message
exchangeStringexchange to be used along with queue/topic to send the message, empty string means the default exchange will be used
optionsMQPublishOptions{}options for sending request
versionObjectversion 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

ParamTypeDefaultDescription
handlerPromisePromise to be called when it is received a message
queueString''queue where to subscribe or '' for autogenerated queue
topicString''topic to bind the queue or '' for none
exchangeString''exchange to be used for queue and topic or '' for default
optionsObject{}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)

ParamTypeDefaultDescription
nameStringrouter name
checkIntervalNumber200check 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

ParamTypeDescription
serializedMessageBuffermessage to be sent
idStringmessage id
optionsObjectmessage 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

ParamTypeDefaultDescription
idStringmessage id
messageBufferresponse message
errorObjecterror to be sent to handler

requestsRoutingTable.setMessagesTimeoutListener(emitter) ⇒ undefined

Setter for event emitter

Kind: instance method of RequestsRoutingTable
Access: public

ParamTypeDescription
emitterEventEmitterevent 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

NameTypeDescription
ttlNumberttl in seconds for the message

TODO

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

LICENSE

MIT