example-simple.coffee | |
---|---|
AmqpDsl = require 'amqp-dsl'
AmqpDsl | |
First we log in, here the list of the available parameters and their default value | .login(
login: 'legen'
password: 'dary'
)
|
Bind listeners to some events (available events are | .on('close', () -> console.error "RabbitMQ connection closed")
.on('error', (err) -> console.error "RabbitMQ error", err)
.on('ready', () -> console.log "Connected to RabbitMQ") |
We create a queue (
| .queue('testQueue', (queue) -> console.log "Connected to Queue", queue.name) |
(optional) ... and bind that queue to an exchange with
| .bind('stream', '#') |
(optional) ... and subscribe for messages (without
| .subscribe((message, header, deliveryInfo) -> )
|
Create another queue | .queue('queue2')
.bind('search', '#.ok')
|
Connect to an existing queue | .queue('queue3', passive:true, (queue)-> console.log "Connected to Queue", queue.name) |
And now it's time to connect !
| .connect((err, amqp) ->
if err
throw err
return
console.log 'We are connected !' |
Do other stuff with | queue3 = amqp.queues.queue3
queue3.subscribe(ack:true, (message) ->
console.log "Hey ! We got one new message !"
queue3.shift()
)
)
|