AMQP Service
| Download only 1.2.0+
versions only, cause lower versions contain bugs
AMQP service which can fetch and send messages to queues
Usage
Config
# Advanced Message Queue Protocol settings
amqp:
# AMQP Server settings
# You can read more about this settings [here](http://www.squaremobius.net/amqp.node/channel_api.html#connect)
server:
protocol: 'amqp'
hostname: 'localhost'
port: 5672
username: 'guest'
password: 'guest'
vhost: '/'
locale: 'en_US'
frameMax: 0
heartbeat: 60
# The Queues which will be added to program
# Note that you can change only value of this keys, cause keys are hardcoded in code
queues:
# Name of the Queue
# Params of the Queue
# You can read more about this params [here](http://www.squaremobius.net/amqp.node/channel_api.html#channel_assertQueue)
# Event that triggers when consumer receive msg from this queue
# Your event handler will receive deserialized and parsed msg
- name: 'first_queue'
params:
durable: false
event: 'on_amqp_first_queue'
- name: 'second_queue'
params:
durable: false
event: 'on_amqp_second_queue'
Code in project
const amqpService = new AMQPService(
config.get('amqp.server'),
config.get('amqp.queues')
);
await amqpService.start();
// If you want to stop AMQP Service use `amqpService.stop()`
// If you want to send Message to queue:
await amqpService.sendMessage('first_queue', {
hello: 'world'
});
// If you want to handle messages from queue:
amqpService.on('on_amqp_first_queue', msg => {
...
});