dammina
dammina

Reputation: 655

ActiveMQ java client startup hangs when server is unavailable

I'm trying to implement a monitoring service for an ActiveMQ server. There I have implemented a polling service to connect to the ActiveMQ server periodically and do a queue browse operation to do a health check on ActiveMQ Server.

Here is the code snippet that I use to start the connection.

ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory(amqUrl);
connectionFactory.setTrustStore(amqSslTrustStorePath);
connectionFactory.setTrustStorePassword(amqSslTrustStorePasswd);
connectionFactory.setKeyStore(amqSslKeyStorePath);
connectionFactory.setKeyStorePassword(amqSslKeyStorePasswd);
Connection connection = connectionFactory.createConnection(amqUser, amqPasswd);
connection.start();

The issue is when the server is unavailable the connection.start() call hangs without throwing an error. For the monitoring purpose I need to detect this.

Am I doing anything wrong here or is there any better way to do this?

UPDATE: This happens only when I use a failover based ActiveMQ url (eg: failover:(ssl://192.168.1.112:61617,ssl://192.168.1.112:61619)?randomize=false otherwise it does work as expected, that is it throws a JMSException (eg: ssl://192.168.1.112:61617)

Upvotes: 3

Views: 940

Answers (1)

Hassen Bennour
Hassen Bennour

Reputation: 3913

So for failover transport :

maxReconnectAttempts: Default Value = -1 | 0

From ActiveMQ 5.6: default is -1, retry forever. 0 means disables re-connection, e.g: just try to connect once. Before ActiveMQ 5.6: default is 0, retry forever. All ActiveMQ versions: a value >0 denotes the maximum number of reconnect attempts before an error is sent back to the client.

Upvotes: 1

Related Questions