0

I can't seem to get a confirm back when I publish to the default exchange. I'm currently using the master branch of node-amqp suggested by this post.

Code:

var amqp = require('amqp');
var conn = amqp.createConnection({ host: 'localhost' });

conn.once('ready', function () {
    conn.publish('test_queue', 'test message', { /* empty options */ }, function (a, b) {
        console.log('Publish complete.');
    });
});

I believe the default exchange is a direct exchange with an empty string (all other options are default). According to the exchange.publish method, if the confirm option is true, it will call the callback supplied. I tried to create the exchange myself, but no luck there either.

var amqp = require('amqp');
var conn = amqp.createConnection({ host: 'localhost' });

conn.once('ready', function () {
    conn.exchange('', { confirm: true }, function (exchange) {
        exchange.publish('test_queue', 'test message', { /* empty options */ }, function (a, b) {
            console.log('Publish complete.');
        });
    });
});

I can confirm that I am successfully publishing the messages by using the the basic python receive script from the RabbitMQ website.

Does the default exchange emit an ack message within the publish method? Am I calling this incorrectly?

Community
  • 1
  • 1
matth
  • 6,112
  • 4
  • 37
  • 43

1 Answers1

0
  1. You need to connect to the queue before publishing, just providing the queue name in the call to publish is not enough.
  2. You need to bind the queue to the exchange, or publish will not work.

Something like:

connection.queue("test_queue", function(q) {
    q.bind(exchange, function() {
        exchange.publish(...);
    }
});

This will make your message go into the specified queue with your new exchange, and the callback will be made. If you're like me and didn't read documentation properly, not that the callback from publish will send false to indicate success (i.e. errorHasOccured is first argument to callback).

Anders Bornholm
  • 1,326
  • 7
  • 18
  • I'm not 100% sure but I think this does not apply to the default exchange (queues are bound to it by default). When I try to do that I get a 403 "operation not permitted on the default exchange" error. – Guido Apr 14 '14 at 10:29
  • 1
    Yes, the point is that you need to create a different exchange since the default doesn't confirm that a message has been successfully published. – Anders Bornholm Apr 15 '14 at 12:19