【发布时间】:2019-08-20 21:42:58
【问题描述】:
问题是我定义了一些可能处于非活动状态的代理 uri。
然后来自ActiveMQConnectionFactory 的createConnection 不会抛出任何异常。我需要处理这种情况,如果 createConnection 由于 uri 不可用而无法工作,那么我应该将我的服务标记为不健康。
boolean healthy = true;
Connection conn = null;
try {
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("failover:(tcp://localhost:8080)?jms.prefetchPolicy.all=0&initialReconnectDelay=1000&maxReconnectDelay=30000&maxReconnectAttempts=20");
conn = factory.createConnection(this.userName, this.password);
} catch (JMSException e) {
healthy = false;
} finally {
if (conn != null) {
try {
conn.close();
} catch (JMSException e) {
healthy = false;
}
}
}
【问题讨论】:
-
故障转移:(tcp://localhost:8080)?jms.prefetchPolicy.all=0&initialReconnectDelay=1000&maxReconnectDelay=30000&maxReconnectAttempts=20
-
没错,就是这样。不,我没有尝试创建会话。我会试试这个并告知。
标签: java spring spring-boot activemq