-
Notifications
You must be signed in to change notification settings - Fork 9
/
example.js
35 lines (31 loc) · 828 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var amqp = require('amqp')
var config = {
connection: {
url: 'amqp://guest:guest@localhost:5672'
},
exchange: {
name: 'logExchange',
type: 'fanout',
durable: true,
autoDelete: false
},
queue: {
name: 'logQ',
durable: true,
autoDelete: false
}
}
var onReady = function () {
// create exchange and queue (if they don't exist) and bind the queue to the exchange
connection.removeListener('ready', onReady)
connection.exchange(config.exchange.name, config.exchange, function (exchange) {
connection.queue(config.queue.name, config.queue, function (queue) {
queue.bind(exchange, '*')
queue.subscribe(function (message) {
console.log(message)
})
})
})
}
var connection = amqp.createConnection(config.connection)
connection.on('ready', onReady)