// Consume the message... MessageConsumer consumer = session.createConsumer(queue); Message msg = consumer.receive(60000); assertNotNull(msg); session.close();
consumer.receive(6000); ### timeout 6000 表示若是队列中没有元素的时候,再次去队列取元素的时间间隔。默认单位是微秒。 若是是 0 就表示阻塞等待,直到元素到来。html
Configuration Syntaxgit
failover:(uri1,...,uriN)?transportOptions&nestedURIOptions
github
orapache
failover:uri1,...,uriN
session
能够经过设置maxReconnectAttempts和maxReconnectDelaydom
多个参数之间用&tcp
failover:(tcp://local:61616,tcp://remote:61616)?randomize=false&priorityBackup=true
Example:spa
failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100
randomize=false
randomize=false 能够设置优先链接放在第一位的 servercode
http://activemq.apache.org/failover-transport-reference.html
下面配置是亲自实践过,当一个MQ有问题后,可以在大约10秒钟左右完成快速切换到有效的 MQ server上面的配置。
failover://(tcp://XXXX:61616,tcp://XXXXX:61616)?nested.wireFormat.maxInactivityDuration=3000&n ested.connectionTimeout=2000&maxReconnectAttempts=2&timeout=2000&initialReconnectDelay=50&startupMaxReconnectAttempts=2&maxRe connectDelay=100
发现activemq说明文档不是很清楚,能够参考redhat 的说明:
如何完成快速切换呢?
Connections are monitored by:
KeepAliveInfo
message to the connection if no normal activemq traffic is sent across the connection during the specified time period.原来每一个链接都是有两个监控的monitor,当maxInanctivityDuration时间里面没有消息的时候,就会发送keepAliveInfo心跳信息,不然sever就会认为这个链接已经失效了,能够关闭了。