postwait / node-amqp

[UNMAINTAINED] node-amqp is an AMQP client for nodejs
MIT License
1.7k stars 357 forks source link

connection publish callback not executed #473

Open vilten opened 5 years ago

vilten commented 5 years ago

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() }) })

lcjury commented 5 years ago

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()
        });
    });
});