How to see which host we connected to
<p>Using RabbitMQ with a cluster of nodes, I set up my factory and connection like this (using the .NET client):</p>

<pre><code>var factory = new ConnectionFactory() 
{ 
    UserName = Properties.Settings.Default.RabbitMQUser,
    Password = Properties.Settings.Default.RabbitMQPassword,
    HostnameSelector = new RandomHostNameSelector(),
    AutomaticRecoveryEnabled = true
};
connection = factory.CreateConnection(Properties.Settings.Default.RabbitMQServers.Split(';'));
</code></pre>

<p>Where <code>Properties.Settings.Default.RabbitMQServers</code> is use a semi-colon delimited list of servers:</p>

<pre><code>clust01;clust02;clust03
</code></pre>

<p>After connecting, is there a way to see <em>which</em> host it actually picked and is there a way to detect when that might change (because the particular node crashed, was stopped, or rebooted)? <code>factory.HostName</code> just returns <code>localhost</code>.</p>

<p><strong>Edit:</strong> It seems <code>connection.Endpoint.HostName</code> does give you the actual host name as @Evk and @wally have both stated (thank you). But is there a way to detect a change? It seems that <a href="https://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.6.2/rabbitmq-dotnet-client-3.6.2-client-htmldoc/html/type-RabbitMQ.Client.IConnection.html" rel="nofollow">IConnection</a> has a <code>ConnectionShutdown</code> event which <em>I guess</em> might be called as part of switching hosts, but there isn't a corresponding start up or restart event (so I'm assuming it wouldn't know the new host yet). There are also <code>ConnectionBlocked</code> and <code>ConnectionUnblocked</code> events, but they are undocumented so I have no idea what they do...</p>