amqp / rhea

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

connection_detail does not support hostname #411

Open jllansford opened 9 months ago

jllansford commented 9 months ago

When using rhea to connect via ssl to our redhat amqp interconnect routers we need to specify the hostname parameter n the connection options or else we get an error about being rejected by local policy.

My understanding from the documentation is that hostname should default to host, however for us the connection fails unless specifically setting hostname to the same value that we use for host. (is this a bug?)

Bug or not setting hostname is trivial enough to do until we attempt to build in our failover. The hostname parameter from within the return value of the connection_details function does not appear to be supported.

grs commented 8 months ago

It should be possible to include the hostname in the options field of the object returned by connection_details. Does that work for you?

jllansford commented 7 months ago

Sorry for the late response I was occupied by some personal things.

Returning hostname in the connection_details function does not appear to work.

grs commented 7 months ago

Sorry, bad advice first time round! You should be able to pass the hostname when using connection_details like this:

var container = require('rhea');

var options = {
    connection_details: function() {
        return {
            port: 5672,
            host: 'localhost',
        };
    },
    hostname: 'my-hostname'
};

container.connect(options);
jllansford commented 7 months ago

Sorry, bad advice first time round! You should be able to pass the hostname when using connection_details like this:

var container = require('rhea');

var options = {
    connection_details: function() {
        return {
            port: 5672,
            host: 'localhost',
        };
    },
    hostname: 'my-hostname'
};

container.connect(options);

I'm not in the office right now so I can't test it. I believe my issue is that the hostname value needs to match the remote hostname of the broker.

So if we have a load-balanced set up with 4 brokers (broker1 - broker4) the connection_details function returns port: 5672, and one of the 4 host values (broker1 - broker4). However the hostname property does not seem supported as part of connection_detail function.

If we initialize hostname to "broker1", then when we fail over to broker2 - broker4 we get an error about a bad hostname. Any attempts to update the hostname property after initialization were not working for us.

grs commented 7 months ago

I see what you mean now. Unfortunately the hostname in the open frame is not reset from options after the initial creation of the connection. This is actually independent of whether you are using connection_details. The only way at present to change it is to set it manually, e.g.

var container = require('rhea');
var connection;
var hostnames = ['foo', 'bar'];
var count = 0;

var options = {
    connection_details: function() {
        if (connection) {
            count = count + 1;
            var hostname = hostnames[count % hostnames.length];
            connection.local.open.hostname = hostname
        }
        return {
            port: 5672,
            host: 'localhost',
        };
    },
    hostname: hostnames[0],
};

connection = container.connect(options);