-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
21 lines (18 loc) · 815 Bytes
/
main.js
File metadata and controls
21 lines (18 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const { Rabbit } = require('rabbit-queue');
const rabbit = new Rabbit(process.env.RABBIT_URL || 'amqp://localhost', {
prefetch: 1, //default prefetch from queue
replyPattern: true, //if reply pattern is enabled an exclusive queue is created
scheduledPublish: false,
prefix: '', //prefix all queues with an application name
socketOptions: {} // socketOptions will be passed as a second param to amqp.connect and from ther to the socket library (net or tls)
});
rabbit.on('connected', () => {
console.log('connected');
//create queues, add halders etc.
//this will be called on every reconnection too
});
rabbit.on('disconnected', (err = new Error('Rabbitmq Disconnected')) => {
//handle disconnections and try to reconnect
console.error(err);
setTimeout(() => rabbit.reconnect(), 100);
});