xardas
xardas

Reputation: 296

amqp exchanges are not auto-deleted

I have rabbitmq 3.3.5 running and nodejs project based on amqplib 0.2.1

The problem is that once exchange has been asserted it does not deleted after connection to rabbitmq is closed.

If we start such example

var amqp = require('amqplib');
var when = require('when');

amqp.connect('amqp://localhost').then(function(conn) {
  return when(conn.createChannel().then(function(ch) {
    var ex = 'logs_new';
    var ok = ch.assertExchange(ex, 'fanout', {durable: false, autoDelete: true}})

    var message = process.argv.slice(2).join(' ') ||
      'info: Hello World!';

    return ok.then(function() {
      ch.publish(ex, '', new Buffer(message));
      console.log(" [x] Sent '%s'", message);
      return ch.close();
    });
  })).ensure(function() { conn.close(); });
}).then(null, console.warn);

and run

#rabbitmqctl list_exchanges

Listing exchanges ...

amq.rabbitmq.log        topic
amq.rabbitmq.trace      topic
amq.topic       topic
logs_new    fanout
...done.

Though connection to rabbitmq was closed, but exchange (logs_new) still persists.

How to tell rabbitmq that exchange needs to be deleted if it is not used by any connection ?

edit: As it is stated at http://www.squaremobius.net/amqp.node/doc/channel_api.html autoDelete option should be 'true'. but nevertheless even exchange with new name is not deleted. What could be wrong?

Upvotes: 1

Views: 4072

Answers (1)

eandersson
eandersson

Reputation: 26362

You should set the auto_delete flag to True when declaring the exchange. This will automatically delete the exchange when all channels are done with it.

Keep in mind that this means that it will stay as long as there is an active binding to the exchange. If you delete the binding, or queue, the exchange will be deleted.

If you need to keep the queue, but not the exchange you can remove the binding once you are done publishing. This should automatically remove the exchange.

Upvotes: 5

Related Questions