Reputation: 3912
I have the following code:
_connectionFactory = new Apache.NMS.ActiveMQ.ConnectionFactory(_activeMqSettings.Connection.ServerUrl, "MyApplication");
_connection = _connectionFactory.CreateConnection(_activeMqSettings.Connection.UserName, _activeMqSettings.Connection.Password);
_connection.ConnectionInterruptedListener += _connection_ConnectionInterruptedListener;
_connection.ConnectionResumedListener += _connection_ConnectionResumedListener;
_session = _connection.CreateSession();
The first connection succeeds, but subsequent connections throw the error:
Broker: localhost - Client: MyApplication already connected from tcp://0:0:0:0:0:0:0:1:39932
this code works ok without the client id, but throws the error with. I was under the impression that giving the ClientId would reconnect to the broker without creating a new session (so the consumer count stays the same), but am I implementing it incorrectly?
When I shut down the website and then restarted it, I can see that the connection resumes as the _connection_ConnectionResumedListener()
fires. My listener however picks up no new messages.
Is there anyway to get a handle on the session, and refresh the listener i.e. re-run:
lock (ConsumerLocker)
{
if (_consumer == null)
{
_consumer = _session.CreateConsumer(new ActiveMQTopic(_activeMqSettings.Queues.OpsConsole));
_consumer.Listener += new MessageListener(messageReader);
}
}
Upvotes: 1
Views: 2272
Reputation: 18356
It's not entirely clear what you are doing in the code, but I can clarify the client ID bits. You need to assign each connection it's own unique client Id if you intend to set that field at all. Any connection attempt using the same client Id made after the initial connection with that client Id will fail until the original connection is closed via a call to connection.Close().
The client Id is generally used on Connection's that are going to have a durable topic subscription associated with them. Each connection must have a unique client Id so that they can recover the durable subscription associated with the Connection, if more than one Connection was allowed to have the same client Id the broker couldn't figure out whose subscriptions are whose.
Upvotes: 1