服务器不可用时 ActiveMQ java 客户端启动挂起
ActiveMQ java client startup hangs when server is unavailable
我正在尝试为 ActiveMQ 服务器实施监控服务。在那里我实现了一个轮询服务来定期连接到 ActiveMQ 服务器并执行队列浏览操作以对 ActiveMQ 服务器进行健康检查。
这是我用来启动连接的代码片段。
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();
问题是当服务器不可用时,connection.start()
调用挂起而没有抛出错误。为了监控目的,我需要检测这个。
我是不是做错了什么或者有更好的方法吗?
更新: 只有当我使用基于故障转移的 ActiveMQ url 时才会发生这种情况(例如:failover:(ssl://192.168.1.112:61617,ssl://192.168.1.112:61619)?randomize=false
否则它会按预期工作,就是这样抛出 JMSException(例如:ssl://192.168.1.112:61617
)
因此对于故障转移传输:
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.
我正在尝试为 ActiveMQ 服务器实施监控服务。在那里我实现了一个轮询服务来定期连接到 ActiveMQ 服务器并执行队列浏览操作以对 ActiveMQ 服务器进行健康检查。
这是我用来启动连接的代码片段。
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();
问题是当服务器不可用时,connection.start()
调用挂起而没有抛出错误。为了监控目的,我需要检测这个。
我是不是做错了什么或者有更好的方法吗?
更新: 只有当我使用基于故障转移的 ActiveMQ url 时才会发生这种情况(例如:failover:(ssl://192.168.1.112:61617,ssl://192.168.1.112:61619)?randomize=false
否则它会按预期工作,就是这样抛出 JMSException(例如:ssl://192.168.1.112:61617
)
因此对于故障转移传输:
maxReconnectAttempts
: Default Value = -1 | 0From 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.