4

I'm using ActiveMQ CPP 5.2.3 if it matters.

I have JMS producer that connects using failover transport to JMS network of brokers. When I call connection->start() it hangs up (see AMQ-2114).

If I skip connection start() and call connection->createSession(), than this call is blocked too.

The requirement is that my application will try forever to connect to broker(s).

Any suggestions/workarounds?

NOTE:

This is not duplicate of here, since I'm talking about C++ and such solutions as embedded broker, spring are not available in C++.

Community
  • 1
  • 1
dimba
  • 26,717
  • 34
  • 141
  • 196

1 Answers1

4

This is normal when the connection is awaiting a transport to connect to the broker. The start method must send the client's id info to the broker before any other operation, so if no connection is present it must block. You can set some options on the failover transport like the startupMaxReconnectAttempts option to control how long it will try to connect before reporting a failure. See the URI configuration page:

http://activemq.apache.org/cms/configuring.html

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • Thanks. But if I use this option connect->start() throws exception. If I ignore the exception than call to connect->createSession() will throw exception. I tried to call connect->createSession() in TransportListener::transportResumed(), but this causes some dead lock in ActiveMQ library. Is there workaround to keep trying to establish the connection in "background"? – dimba Feb 28 '11 at 05:33
  • IMHO, according to JMS specificatioon, conenction->start() can be called after configuration is completed (i.e. call connection->start() after connection->createSession()), but this also doesn't work – dimba Feb 28 '11 at 05:34
  • Nope, the broker needs to know the client Id before an actual session is created. The best thing to do is to allow the client to hang at start, or trip an event when transportResumed is called. You can't create resources on a server that's not there. – Tim Bish Feb 28 '11 at 11:12
  • Let me see if I understand correctly - I can perform connect->start() in separate thread and the thread will be blocked forever till succeed to create a connection. Once connection is create,d transportResumed() is called by ActiveMQ lib on behalf of its thread. Afterwards I need to send an event from transportResumed() to continue initialization (e.g. connection->createSession()) on behalf of other thread. Can I continue initialization directly in transportResumed()? – dimba Feb 28 '11 at 11:39
  • I wouldn't advise attempting to create any resources inside transportResumed, you are quite likely to run into a thread deadlock. The interrupted and resumed callback are really for information purposes only and should be used with care. You could set an event inside them that triggers some other thread. The thread that's waiting on connection.start will resume once a connection is established. – Tim Bish Feb 28 '11 at 20:32