Search code examples
node.jsrabbitmqnode-amqp

amqp rabbitmq channel scope


I'm using amqplib with node.js and I'm trying to make sure I understand the concept of channels.

This is from the amqplib documentation: Channels are multiplexed over connections, and represent something like a session, in that most operations (and thereby most errors) are scoped to channels.

Here is some basic code where I'll open a amqp connection, create a channel, an exchange and a queue:

var amqp = require('amqp/callback_api');
var connection = amqp.createConnection({ host: "localhost", port: 5672 });



connection.on('ready', function () {
    connection.createChannel(function(err, ch) {
        ch.assertExchange('1', 'fanout', function(err, ok) {});
        ch.assertQueue('a', {
            exclusive: true,
            durable: true
        }, function(err, ok) {

        });
    });

In the above code do exchange '1' and queue 'a' only exist on the channel for which they were defined? By this I mean, if I were to publish a messages to exchange a from another channel would exchange a still route the messege?


Solution

  • All entities like exchanges, queues, messages exists globally on the broker and visible to all connections and channels inside single vhost. There are no exceptions from that.

    Queues may be defined as exclusive, then they are exists only within same connection and when it closed they are destroyed. This is special case while as they still visible, they are not accessible from other connections.

    There are auto-delete option for both queues and exchanges, which is by default set to true. It means that they will be removed after usage (see exchange and queue auto-delete docs for details).