Cluster Setup and Connection string C#

606 views
Skip to first unread message

Timir Panchal

unread,
Sep 9, 2015, 4:51:12 PM9/9/15
to rabbitmq-users
Hello RebbitMQ Users,

We have RabbitMQ Cluster setup on Server1 and Server2.

I am using RebbitMQ.Client C# library to interact with RebbitMQ. 

While creating connection using ConnectionFactory I can specify URL to connect to either server1 OR Server2.

If I specify server1 uri at the time of connection and if server1 goes down it is not switching to Server2.

What I need to do to\setup connection string so that it handles a fail-over and works fine if one server goes down.

Thank you for your reply.

-Timir Panchal

Michael Klishin

unread,
Sep 9, 2015, 4:55:36 PM9/9/15
to rabbitm...@googlegroups.com, Timir Panchal
On 9 Sep 2015 at 23:51:15, Timir Panchal (timi...@gmail.com) wrote:
> While creating connection using ConnectionFactory I can specify
> URL to connect to either server1 OR Server2.
>
> If I specify server1 uri at the time of connection and if server1
> goes down it is not switching to Server2.
>
> What I need to do to\setup connection string so that it handles
> a fail-over and works fine if one server goes down.

The client used to support endpoint lists but when we introduced automatic
connection recovery, it was temporarily removed. It will be back in 3.6.0:
https://github.com/rabbitmq/rabbitmq-dotnet-client/pull/92 (and thus is already
in nightly builds: https://www.rabbitmq.com/nightly-builds.html).

Without it, you need to use a load balancer/proxy in front of your cluster.
It can reside on the app node, this way the proxy won’t be a SPoF
(provided there’s more than one app node). 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Timir Panchal

unread,
Sep 9, 2015, 5:06:18 PM9/9/15
to rabbitmq-users, timi...@gmail.com
Thank you!
Do you mean it us available in Nightly build and if I down load latest I can get that functionality?
Any Idea when 3.6.0 is releasing?

Michael Klishin

unread,
Sep 9, 2015, 5:37:20 PM9/9/15
to rabbitm...@googlegroups.com, Timir Panchal
On 10 Sep 2015 at 00:06:21, Timir Panchal (timi...@gmail.com) wrote:
> Do you mean it us available in Nightly build and if I down load
> latest I can get that functionality?

Correct.

> Any Idea when 3.6.0 is releasing?

In  November.

Timir Panchal

unread,
Sep 14, 2015, 4:46:02 PM9/14/15
to rabbitmq-users, timi...@gmail.com
Thanks Michael,

I tried to do as you specified but some how I am not able to create connection.

Is there any sample code that you can point me.

Appreciate your help.

Thanks
Timir

Michael Klishin

unread,
Sep 15, 2015, 1:52:22 AM9/15/15
to rabbitm...@googlegroups.com, Timir Panchal
On 14 September 2015 at 23:46:05, Timir Panchal (timi...@gmail.com) wrote:
> I tried to do as you specified but some how I am not able to create
> connection.
>
> Is there any sample code that you can point me.

https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/master/projects/client/Unit/src/unit/TestConnectionRecovery.cs#L108

Timir Panchal

unread,
Sep 15, 2015, 2:29:25 PM9/15/15
to rabbitmq-users, timi...@gmail.com
Thanks!

I looked at the sample and change my code. Here is my code snippet.

 List<string> hosts = new List<string>();
                URIs.ForEach(u => hosts.Add("10.XX.XX.XX"));

                try
                {
                    _connection = _factory.CreateConnection(hosts);
                }
                catch (Exception ex)
                {
                }

I got broker unreachable exception. And inner exception says:
InnerException {"No connection could be made because the target machine actively refused it 127.0.0.1:5672"}

Why it shows local host? Any Idea.

Thanks for all your help.

Michael Klishin

unread,
Sep 15, 2015, 3:05:04 PM9/15/15
to rabbitm...@googlegroups.com, timi...@gmail.com
if your list is empty because there are no URIs, the client will fall back to localhost.

Could be a client bug, too, but you see this feature in action in the test suites.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Timir Panchal

unread,
Sep 15, 2015, 3:15:15 PM9/15/15
to rabbitmq-users, timi...@gmail.com
I checked list and it has one entry.

Timir Panchal

unread,
Sep 15, 2015, 4:28:38 PM9/15/15
to rabbitmq-users, timi...@gmail.com
Looks like there is a bug in Client code.

this._factory.HostName = "10.xx.xx.xx";

if I do above at the time of creating a factory I am able to connect.

If I am specifying host names in create connection then why I need host name while create factory?

Here is what I found:
In Connection Factory - Default host name set to:
public string HostName = "localhost";

Here is a code to Get\set end points:
public AmqpTcpEndpoint Endpoint
    {
      get
      {
        return new AmqpTcpEndpoint(this.HostName, this.Port, this.Ssl);
      }
      set
      {
        this.Port = value.Port;
        this.HostName = value.HostName;
        this.Ssl = value.Ssl;
      }
    }

CreateConnection(HostList) calls:
 this.m_factory.CreateFrameHandler(this.m_factory.Endpoint.CloneWithHostname(hostname2));

protected void Init(string hostname) - Takes in host name bu not use it at all.


public IFrameHandler CreateFrameHandler()
    {
      return Protocols.DefaultProtocol.CreateFrameHandler(this.Endpoint, this.SocketFactory, this.RequestedConnectionTimeout);
*** this.EndPoint is localhost here and it fails
    }

Please let me know if I am not doing something right.

Thanks
Timir

Michael Klishin

unread,
Sep 15, 2015, 5:20:51 PM9/15/15
to rabbitm...@googlegroups.com, Timir Panchal
On 15 Sep 2015 at 23:28:42, Timir Panchal (timi...@gmail.com) wrote:
> this._factory.HostName = "10.xx.xx.xx";
>
> if I do above at the time of creating a factory I am able to connect.
>
> If I am specifying host names in create connection then why I need
> host name while create factory?

Because historically the client supported connecting to a single host only.
We can’t just scrap that part of the API.

> Here is what I found:
> In Connection Factory - Default host name set to:
> public string HostName = "localhost";
>
> Here is a code to Get\set end points:
> public AmqpTcpEndpoint Endpoint
> {
> get
> {
> return new AmqpTcpEndpoint(this.HostName, this.Port, this.Ssl);
> }
> set
> {
> this.Port = value.Port;
> this.HostName = value.HostName;
> this.Ssl = value.Ssl;
> }
> }
>
>
> CreateConnection(HostList) calls:
> this.m_factory.CreateFrameHandler(this.m_factory.Endpoint.CloneWithHostname(hostname2));
>
> protected void Init(string hostname) - Takes in host name bu
> not use it at all.
>
>
> public IFrameHandler CreateFrameHandler()
> {
> return Protocols.DefaultProtocol.CreateFrameHandler(this.Endpoint,
> this.SocketFactory, this.RequestedConnectionTimeout);
> *** this.EndPoint is localhost here and it fails
> }

The issue seems to be that the list of hosts is only used during recovery.
We need to iterate over endpoints until one of them succeeds, for the initial
connection as well. 

Timir Panchal

unread,
Oct 6, 2015, 5:23:12 PM10/6/15
to rabbitmq-users, timi...@gmail.com
Michale,

Sorry I got other priority and had to drop this but now back to it.

As I mentioned I have 2 nodes. I created list of host and send the list at the time of opening connection.

I am able to open connection only if both nodes are up. If i stop any node (rabbitmqctl stop_app) , I am not able to open connection. The exception says "Not able to reach any of the end point".

Any suggestions?

Thanks
Timir

Michael Klishin

unread,
Oct 6, 2015, 5:29:03 PM10/6/15
to rabbitm...@googlegroups.com, Timir Panchal, timi...@gmail.com
On 7 Oct 2015 at 00:23:16, Timir Panchal (timi...@gmail.com) wrote:
> I am able to open connection only if both nodes are up. If i stop
> any node (rabbitmqctl stop_app) , I am not able to open connection.
> The exception says "Not able to reach any of the end point".
>
> Any suggestions?

As I explained earlier, this may be a bug (or an incomplete feature, if you will).

We will take a look for 3.5.7. Thanks for clarifying. 
Reply all
Reply to author
Forward
0 new messages