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.

  • Broker installation The docker compose uses functionalities that require the Broker to be deployed into a swarm. Inside the docker-compose folder run the script: docker stack deploy --compose-file docker-compose.yml rabbitmq

  • File locations

│ node : rabbit@02ee72e2d91d │ home dir : /var/lib/rabbitmq │ config file(s) : /etc/rabbitmq/rabbitmq.conf │ cookie hash : mhyXR2KVaxqoFFCCKR907g== │ log(s) : │ database dir : /var/lib/rabbitmq/mnesia/rabbit@02ee72e2d91d

  • RabbitMQ Info - Through rabbitmqctl plugin Config File location: /etc/rabbitmq/rabbitmq.conf

    • List users - shows all registered users and their tags

    rabbitmqctl list_users

    • Add user - adds one user (without management tag)

    rabbitmqctl add_user user_name password

    • Set user tags - defined the management role

    rabbitmqctl set_user_tags user_name management_tag

    • Set permissions

    rabbitmqctl set_permissions -p /host_name user_name “^tonyg-.” “.” “.*”

    • List permissions

    rabbitmqctl list_permissions -p /host_name

  • ConfigFileStructure: vfos_messaging_pubsub_config.conf loopback_users.guest = false listeners.tcp.default = 5672 hipe_compile = false management.listener.port = 15672 management.listener.ssl = false auth_http.user_path = auth_http.vhost_path = auth_http.resource_path = auth_http.topic_path =



In this library's folder run

npm install


vfosMessagingPubsub = require('lib-messaging-pub-sub-js');


communicationObject = new vfosMessagingPubsub("amqp://", "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


Connect to the messaging system


Disconnect from the messaging system


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 from the messaging system and delete our queues


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)


Check our messaging queue for private messages

Provide a callback (function) for handling each retrieved message object


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 are avaliable in examples/


[1] - RabbitMQ