Skip to content

Allow IHostanameSelector to return a dynamically resolved hostname #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alessnet opened this issue Jun 7, 2016 · 9 comments
Closed

Comments

@alessnet
Copy link

alessnet commented Jun 7, 2016

Hello,

I'm using a service-discovery which gives me the latest list of addresses for Rabbitmq servers (and which ones are in the same datacenter). So the addresses are not hard-coded in the client configuration. The list is dynamic and can change when servers goes down or up.

The issue with the current rabbit client if that we have to give a static list of hosts when creating the connection. When the connection is lost, we can specify the new host using IHostnameSelector. But we may want to return an host that was not originally in the list (because the could have changed in the meantime, especially if this is a long running process).

So in IHostnameSelector.NextFrom(list), is it ok to return an host name that was not in the original list ?
If not, how could we provide a new list when a recovery occurs, without recreating the whole connection?

Thank you

@kjnilsson
Copy link
Contributor

Hi @alessnet - can you please direct your question to the rabbitmq-users mailing list. We use github issues for actionable items only. Cheers.

@alessnet
Copy link
Author

alessnet commented Jun 7, 2016

@kjnilsson

The action item here would be to add this functionality if missing, or clarify the documentation if this is possible using the existing IHostnameSelector.
I read the source code, but I wanted to be sure that's why I created this issue as a question.

Sorry for the inconvenience

@kjnilsson
Copy link
Contributor

Ok from looking at the code it looks like having IHostnameSelector returning an arbitrary endpoint might have worked in the past but won't work with the current version. So the feature request is to somehow allow users to specify an arbitrary endpoint resolution strategy?

@kjnilsson kjnilsson reopened this Jun 7, 2016
@kjnilsson kjnilsson changed the title Dynamic list of host names when recovery occurs Allow IHostanameSelector to return a dynamically resolved hostname Jun 7, 2016
@michaelklishin
Copy link
Contributor

IHostnameSelector operates on a known list of hosts but a new object (and a new interface) can be introduced that would provide that list.

@kjnilsson
Copy link
Contributor

I suggest we add an IEndpointSelector with NextFrom (endpoints) -> AmqpTcpEndpoint function and mark IHostnameSelector as obsolete.

@michaelklishin
Copy link
Contributor

We can do that but it's not the point of this issue. This issue is about producing a list of endpoints or hostnames dynamically.

@kjnilsson
Copy link
Contributor

The new interface would allow you to return an arbitrarily resolved endpoint, say, resolved from round-robin dns but perhaps it isn't a particularly intuitive interface as you'd have to ignore the endpoints provided to NextFrom. I'll look at some other options.

@kjnilsson
Copy link
Contributor

I'm going to start implementation of this for v4. As we can impose some smaller breaking changes I suggest we change IHostnameSelector to IEndpointSelector and make sure the interface is consistent with and works with the above scenario. This may require a few ConnectionFactory refactorings and API changes.

@kjnilsson
Copy link
Contributor

Created PR for this now which introduces the IEndpointResolver interface used for returning a collection of AmqpTcpEndpoints that the connection factory will try to connect to in the order returned. To make the connection factory used a different IEndpointResolver than the default set the EndpointResolverFactory function on the ConnectionFactory instance.

Here is a simple untested example of an IEndpointResolver that could be used with round-robin DNS to provide a list of endpoints:

    public class DnsEndpointResolver : IEndpointResolver
    {
        private string hostname;
        private int port;
        public DnsEndpointResolver(string hostname, int port)
        {
            this.hostname = hostname;
            this.port = port;
        }
        public IEnumerable<AmqpTcpEndpoint> All()
        {
            return System.Net.Dns.GetHostEntry(hostname).AddressList
                                .Select(a => new AmqpTcpEndpoint(a.ToString(), port));
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants