npm install @itavy/mq-router
- MQRouter
Class MQRouter
- RequestsRoutingTable
MQRequestsRoutingTable class
- itavy/mq-router :
object MQRouter module
- MQPublishOptions :
Object
Class MQRouter
Kind: global class
- MQRouter
- new MQRouter(mqURI, [connector], mqMessage, mqKnownMessages, mqDefaultMessageVersion, name, [queue], [topic], [exchange], [errorCollector], [defaultHandler], [defaultTTL])
- .sendMessage(message, version, queue, exchange, [options]) ⇒
Promise - .sendRequest(message, queue, exchange, [options], version) ⇒
Promise - .subscribe(handler, [queue], [topic], [exchange], [options]) ⇒
Promise - .close() ⇒
Promise
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 |
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 |
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 |
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 |
Close stops checks for expired messages and close connection
Kind: instance method of MQRouter
Returns: Promise - resolves when connection is closed
Access: public
MQRequestsRoutingTable class
Kind: global class
- RequestsRoutingTable
- new RequestsRoutingTable(name, [checkInterval])
- .register(serializedMessage, id, options) ⇒
Promise - .callById(id, [message], [error]) ⇒
Boolean - .setMessagesTimeoutListener(emitter) ⇒
undefined - .close() ⇒
undefined
| Param | Type | Default | Description |
|---|---|---|---|
| name | String |
router name | |
| [checkInterval] | Number |
200 |
check interval in ms to see if requests have passed their ttl |
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 |
Resolve a request
Kind: instance method of RequestsRoutingTable
Returns: Boolean - true if listener exists
Throws:
IErrorif 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 |
Setter for event emitter
Kind: instance method of RequestsRoutingTable
Access: public
| Param | Type | Description |
|---|---|---|
| emitter | EventEmitter |
event emitter |
Stops checks for expired messages
Kind: instance method of RequestsRoutingTable
Access: public
MQRouter module
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| ttl | Number |
ttl in seconds for the message |
- more examples and better documentation
- more e2e testing
- refactor tests for nodejs 6