在将消息发布到队列后尝试关闭ActiveMQ连接时,Java线程将挂起,因为该连接永远不会关闭。我们可以在代理URL上添加其他逻辑或其他属性,以使尝试关闭的连接超时吗?
我们正在使用具有TCP连接的故障转移传输。这是我们尝试关闭连接的代码段。在finally块中,尝试执行connection.close时,它永远不会关闭并继续运行,因此将阻止消耗此队列上的所有将来消息。
仅供参考。这是一个Grails 3.2.4项目
try {
MessageProducer producer = session.createProducer(session.createQueue(queueName))
TextMessage textMessage = session.createTextMessage(message)
textMessage.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, resendTime)
if (correlationId) {
textMessage.setJMSCorrelationID(correlationId)
}
producer.send(textMessage)
} finally {
log.debug("Attempting to close the session after sending message to queue ${queueName}. Message = ${message}")
session.close()
log.debug("Attempting to close the connection after sending message to queue ${queueName}. Message = ${message}")
if (connection) {
connection.close()
} else {
log.warn("No connection exists while attempting to close after sending message to queue ${queueName}. Message = ${message}")
}
}
这是我们的联系的片段:
brokerURL: 'failover:(tcp://serverAddress:port,vm://localhost)?initialReconnectDelay=5000&maxReconnectDelay=10000&timeout=5000&randomize=false&priorityBackup=true'