activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From philipyao <phi...@web2printexperts.com>
Subject ApacheNMS: How to "Open" a closed connection?
Date Thu, 27 Sep 2012 08:04:28 GMT
Hi guys!

I am new to activeMq and I have some problems when starting a connection
after being created. 
It always throws a ConnectionClosedException which says something like
"Connection is already closed".

I have read attempting to create a connection through a while loop worked
for them but it's has not on my end. :(  
Other attempts, I've tried to 
          - attach "failover:" text on the url. 
          - Using with and without user credentials on creating the
Connection object. 

Below is my code:

                bool connected = false;
                Connection conn =
(Connection)this.ActiveMqConnectionFactory.CreateConnection(
                    "username",
                    "password");

                int times = 0;
                while (!connected)
                {
                    Console.WriteLine("Trying" + times.ToString());
                    try
                    {
                        times++;
                        conn.Start();
                        connected = conn.IsStarted;                        
                    }
                    catch
                    {
                        conn.Dispose();
                        conn =
(Connection)this.ActiveMqConnectionFactory.CreateConnection(
                    "username",
                    "password");
                    }
                }

My question now is there a way to open a connection through code?
By the way, I dont have a clientId when creating an instance of the
Connection Factory, I only use the one with only the url as the parameter. 
So basically, I am assuming that I am connecting through the
defaultClientId.  Also, does the clientId really matter when starting
connections?

Any help would be greatly appreciated!

Thanks!
Philip



--
View this message in context: http://activemq.2283324.n4.nabble.com/ApacheNMS-How-to-Open-a-closed-connection-tp4657075.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message