一 设置消费者等待产品到来等待时间
// Consume the message...
MessageConsumer consumer = session.createConsumer(queue);
Message msg = consumer.receive(60000);
assertNotNull(msg);
session.close();
consumer.receive(6000); ### timeout 6000 表示如果队列中没有元素的时候,再次去队列取元素的时间间隔。默认单位是微秒。 如果是 0 就表示阻塞等待,直到元素到来。
二 activemq 失败重连设置
2.1 failover activemq 连接失败重连设置
Configuration Syntax
failover:(uri1,...,uriN)?transportOptions&nestedURIOptions
or
failover:uri1,...,uriN
可以通过设置maxReconnectAttempts和maxReconnectDelay
多个参数之间用&
failover:(tcp://local:61616,tcp://remote:61616)?randomize=false&priorityBackup=true
Example:
failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100
2.2 多个连接设置连接优先级
randomize=false
randomize=false 可以设置优先连接放在第一位的 server
http://activemq.apache.org/failover-transport-reference.html
2.3 最有效的快速失败重连配置是
下面配置是亲自实践过,当一个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 的说明:
2.4 快速切换是如何完成的呢?maxInactivityDuration=3000 这个参数是如何工作的?
如何完成快速切换呢?
Connections are monitored by:
- Ensuring data is read from the connection during the specified time period (Max Inactivity Duration).
- Writing a
KeepAliveInfo
message to the connection if no normal activemq traffic is sent across the connection during the specified time period.
原来每个连接都是有两个监控的monitor,当maxInanctivityDuration时间里面没有消息的时候,就会发送keepAliveInfo心跳信息,否则sever就会认为这个连接已经失效了,可以关闭了。
http://activemq.apache.org/activemq-inactivitymonitor.html