Reputation: 908
I'm trying to get acknowledges of delivered and processed messages using RabbitMQ. Unfortunately no success.
Look at my simplified code:
Server:
amqp = require("amqp")
# Open a connection
conn = amqp.createConnection( {url: "amqp://localhost"} , {reconnect: false})
conn.on "ready", ->
console.log "Conn Ready"
conn.queue "queueX", {ack:true}, (queue) ->
console.log "Subscribed #{queue.name}"
# subscribe to that queue
queue.subscribe { ack: true }, (message, headers, deliveryInfo, ack) ->
console.log message
queue.shift() if queue.shift?
Client:
amqp = require("amqp")
# Open a connection
conn = amqp.createConnection( url: "amqp://localhost" , reconnect: false)
conn.on "ready", ->
console.log "Conn Ready"
# declare the default exchange
conn.exchange "exchX", {confirm:true, type:"fanout", autoDelete:true}, (exchange) ->
# create a queue
conn.queue "queueX", (queue) ->
console.log "Subscribed #{queue.name}"
queue.bind exchange, queue.name, ->
# publish a message
console.log "Sending CloudAMQP 1"
exchange.publish "", body:"Hello CloudAMQP 1", {}, (out1)->
console.log "Callback called for msg CloudAMQP 1. Delivered: #{out1}"
# publish a message
console.log "Sending CloudAMQP 2"
exchange.publish "", body:"Hello CloudAMQP 2", {}, (out1)->
console.log "Callback called for msg CloudAMQP 2. Delivered: #{out1}"
Server Output:
Conn Ready
Subscribed queueX
{ body: 'Hello CloudAMQP 1' }
{ body: 'Hello CloudAMQP 2' }
Client Output:
Conn Ready
Subscribed queueX
Sending CloudAMQP 1
Sending CloudAMQP 2
Callback called for msg CloudAMQP 1. Delivered: false
Callback called for msg CloudAMQP 2. Delivered: false
As you can see Delivered is false. Any idea what's wrong with this code?
Upvotes: 1
Views: 2762
Reputation: 1051
This is the way you confirm (acknowledge) the publish
exchange.publish('', {body: 'your body'}, {}, function(err){
if (err) return console.error(err);
console.info('published');
}).addListener('ack', function() {
console.info('ack received');
});
PS: I do not use coffeescript so, excuse me for posting normal javascript :), it's hard for me to convert, if you are having trouble with this I will give it a shot
Upvotes: 1