node-amqp icon indicating copy to clipboard operation
node-amqp copied to clipboard

connection publish callback not executed

Open vilten opened this issue 6 years ago • 1 comments

Hello,

when I tried prepare simple publish procedure, callback after publishing message is never executed.

var amqp = require('amqp')

var connection = amqp.createConnection({ host: 'localhost', port: 5672 })

// add this for better debuging connection.on('error', function(e) { console.log("Error from amqp: ", e) })

// Wait for connection to become established. connection.on('ready', function () { console.log('Connected.') connection.publish('my-queue', '', {}, _ => { console.log('Not executed') connection.end() }) })

vilten avatar Nov 28 '18 17:11 vilten

callback is a function that will get called if the exchange is in confirm mode

You're forced to setup an exchange with the option {confirm: true} to use the callback:

connection.on('ready', function () {
    console.log('Connected.')
    connection.exchange('', {confirm: true}, function(exchange) {
        exchange.publish('my-queue', '', {}, _ => {
            console.log('Executed')
            connection.end()
        });
    });
});

lcjury avatar Mar 20 '19 15:03 lcjury