// 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就會認爲這個鏈接已經失效了,能夠關閉了。