Java ActiveMQ 连接超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20694045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActiveMQ timeout at connection
提问by nucandrei
I have the following problem: I try to connect to an ActiveMQ broker (which is now down) using the following piece of code
我有以下问题:我尝试使用以下代码连接到 ActiveMQ 代理(现在已关闭)
connectionFactory = new ActiveMQConnectionFactory(this.url + "?timeout=2000");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
LOGGER.info("Connected to " + this.url);
The problem is that the timeout does not have any effect
问题是超时没有任何影响
connection.start()
is blocked forever. I inspected ActiveMQ log and found the following info:
永远被封锁。我检查了 ActiveMQ 日志,发现以下信息:
2013-12-20 01:49:03,149 DEBUG [ActiveMQ Task-1] (FailoverTransport.java:786) - urlList connectionList:[tcp://localhost:61616?timeout=2000], from: [tcp://localhost:61616?timeout=2000]
2013-12-20 01:49:03,149 DEBUG [ActiveMQ Task-1] (FailoverTransport.java:1040) - Connect fail to: tcp://localhost:61616?timeout=2000, reason: java.lang.IllegalArgumentException: Invalid connect parameters: {timeout=2000}
The timeout parameter is specified here http://activemq.apache.org/cms/configuring.html
超时参数在此处指定http://activemq.apache.org/cms/configuring.html
Has anybody any idea how to pass timeout argument to ActiveMQConnectionFactory? Or how to set a timeout for connection.start() ? Thank you!
有人知道如何将超时参数传递给 ActiveMQConnectionFactory 吗?或者如何为 connection.start() 设置超时?谢谢!
Update: I found this on Stackoverflow: ActiveMQ - CreateSession failover timeout after a connection is resumed. I tried it but the following exception is thrown:
更新:我在 Stackoverflow 上发现了这个:ActiveMQ - CreateSession failover timeout after a connection is resumed。我试过了,但抛出以下异常:
javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {transport.timeout=5000}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
I use ActiveMQ 5.8.0 from maven repo
我使用来自 maven repo 的 ActiveMQ 5.8.0
采纳答案by Andrew
It appears that your url is invalid still in both cases when attempting to set the timeout property.
在尝试设置超时属性时,您的 url 在这两种情况下似乎仍然无效。
If you're trying to have a failover URL, which it looks like you are since it is getting in to the Failover code then you're probably looking for initialReconnectDelay (and possibly maxReconnectAttempts which would throw an exception if the server is still down after the number of attempts is reached).
如果您正在尝试使用故障转移 URL,它看起来像您,因为它正在进入故障转移代码,那么您可能正在寻找 initialReconnectDelay(可能还有 maxReconnectAttempts,如果服务器在达到尝试次数)。
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover://(tcp://localhost:61616)?initialReconnectDelay=2000&maxReconnectAttempts=2");