File | Date | Author | Commit |
---|---|---|---|
examples | 2018-10-17 | Joao | [baed5d] Software package for R2. |
LICENSE | 2018-03-15 | dll | [d75ecf] Update LICENSE copyright. |
README.md | 2018-10-17 | Joao | [baed5d] Software package for R2. |
index.js | 2018-10-17 | Joao | [baed5d] Software package for R2. |
package.json | 2018-10-17 | Joao | [baed5d] Software package for R2. |
Read Me
lib-messaging-pub-sub-js
JavaScript library to simplify the use of amqplib and RabbitMQ.
AMQP & RabbitMQ
The message broker has a loosely coupled architecture, which allows the components of the system to use the name rather than their location/address. This can only be possible because the broker (RabbitMQ) does all the messaging management. It receives the messages produced by the producers/publishers and will deliver them to the consumers or another broker.
In vfOS project, the message broker will use Advanced Message Queuing Protocol (AMQP), that is an open standard that defines a protocol for components to exchange messages. It is a specification that defines the semantics of an interoperable messaging protocol [1].
In [1] you can find a comparison between AMQP and other message protocols.
vfosMessagingPubsub
Install
In this library's folder run
npm install
Import
vfosMessagingPubsub = require('lib-messaging-pub-sub-js');
Initialize
communicationObject = new vfosMessagingPubsub("amqp://broker.address.com", "username", "vfos.prefix", ["example.key.*", "example.anotherkey.logs"]);
Login and Registry happen automatically on initialization
Avaliable Methods
Upon initializing a vfosMessagingPubsub object, the following methods become avaliable for use
Each of these methods return a promise
login()
Connect to the messaging system
logout()
Disconnect from the messaging system
register(keys)
Register on the messaging system, create our queues and subscribe to topic keys
(string array)
After registering, messages messages will be saved even if the user is offline
unregister()
Unregister from the messaging system and delete our queues
changeSub(keys)
Change the PubSub subscriptions to topic keys
(string array)
sendPrivateMessage(prefix, dest, content)
Send a private message to a component dest
(string) in a location prefix
(string) with content
(multitype)
sendPublication(key, content)
Publish a message on a topic key
(string) with content
(multitype)
registerPrivateMessageReceiver(callback)
Check our messaging queue for private messages
Provide a callback
(function) for handling each retrieved message object
registerPublicationReceiver(callback)
Check our PubSub queue for public messages
Provide a callback
(function) for handling each retrieved message object
Message object
Received messages are resolved in the following format
element | type | description |
---|---|---|
routingKey | string | String with the routing key of the message |
id | string | Identification of the sender |
content | blob | Content of the message |
timestamp | number | Unix time of sending |
length | number | Length of the message |
Each of these functions returns a promise that will resolve if its execution is successful or get rejected otherwise
Examples
Examples are avaliable in examples/
References
[1] - RabbitMQ