Question

Here is my code

    private Connection _connection;

    private ISession _session;

    private const String QUEUE_DESTINATION = "DotNet.ActiveMQ.Test.Topic";

    ConnectionFactory factory;        

    Transpo

    public void TestInitialize()
    {
        factory = new ConnectionFactory("tcp://localhost:61616");

        _connection = factory.CreateConnection("system", "manager") as Connection;

        bool x=_connection.TransportFailed;

        _connection.ClientId = "LFV";//Exception when connection not estab

        _connection.Start();//Exception when connection not estab

        _session = _connection.CreateSession();
    }

I get an exception at _connection.ClientId and _connection.Start. Is there any way i can avoid this exception by finding if the connection has been established or not before calling the start method and assigning the client ID.

Was it helpful?

Solution

If you're not setting a unique client ID then the exception would be expected as only one client can be connected to the broker for any given client Id. If you fix your code such that each client app has it's own unique client Id then the problem should resolve itself. You can of course also set an exception listener on the Connection to get notified of errors.

There is no way to test the connection as it's waiting for you to either set a ClientId or start the connection in order to behave as a JMS client. The actual connection handshake doesn't happen until the start call or any call that would require a fully established connection such as createSession etc. You should code you application to respond to failures from connection start.

Oh and FYI, setting client ID after calling start will have no effect as it is only allowed prior to the start of the Connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top