amqp / rhea

A reactive messaging library based on the AMQP protocol
Apache License 2.0
279 stars 79 forks source link

What is the effect of providing container_id as one of the options while creating a new connection #140

Open amarzavery opened 6 years ago

amarzavery commented 6 years ago
const rhea = require("rhea");
const connectionOptions = {
    transport: "tls",
    host: "localhost",
    hostname:"localhost",
    username: "username",
    password: "password",
    port: 5672,
    reconnect: false,
    container_id: "container-123" // <<<<<<
  };
const connection = rhea.create_connection(options);

I thought that by providing the container_id, rhea will create a new container object with the provided id and then create a connection on that container. However,

This seems a little weird. What is the use case for providing a container_id in the connectionOptions? If provided then what is the effect?

grs commented 6 years ago

It is a way of overriding the container-id sent to the peer in the open frame. It has no impact on the container object the connection is associated with, it just prevents the connection using the id of that associated container instead using the value provided.

The container-id is how the peer will identify the 'container' the connection is being established from. The container in AMQP terminology is roughly analogous to a process. Using a different container id on connections from the same process would cause the peer to treat them as coming from distinct processes.

amarzavery commented 6 years ago

I see. Thanks for the prompt response. I think connection object should have a readonly property named container_id.

Connection.prototype.container_id = this.options.container_id || this.container.id;

This ensures that users will get the right container id when they are using it in their app or are using it for logging purposes. What do you think about it?

grs commented 6 years ago

this.options.container_id will always be the right value, whether it came from the associated container or the application specified it explicitly