activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Gomes <e.se...@gmail.com>
Subject Re: ApacheNMS: How to "Open" a closed connection?
Date Thu, 27 Sep 2012 18:04:19 GMT
Hi Philip,

I would recommend using the higher-level NMSConnectionFactory API as
follows:

IConnectionFactory connectionFactory = new
NMSConnectionFactory("activemq:failover:tcp://activemqhost:61616",
"your-connectionid-here");
IConnection connection = connectionFactory.CreateConnection(userName,
password);
connection.Start();


Hope that helps.
Best,
Jim

On Thu, Sep 27, 2012 at 1:04 AM, philipyao <philip@web2printexperts.com>wrote:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message