activemq 消费者超时设置和失败超时链接测试

 一 设置消费者等待产品到来等待时间

// Consume the message...
        MessageConsumer consumer = session.createConsumer(queue);
        Message msg = consumer.receive(60000);
        assertNotNull(msg);
        session.close();

consumer.receive(6000); ### timeout 6000 表示若是队列中没有元素的时候,再次去队列取元素的时间间隔。默认单位是微秒。 若是是 0 就表示阻塞等待,直到元素到来。html

https://github.com/apache/activemq/blob/master/activemq-unit-tests/src/test/java/org/apache/activemq/ConsumerReceiveWithTimeoutTest.javajava

二 activemq 失败重连设置

2.1 failover activemq 链接失败重连设置

Configuration Syntaxgit

failover:(uri1,...,uriN)?transportOptions&nestedURIOptionsgithub

orapache

failover:uri1,...,uriNsession

能够经过设置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

2.2 多个链接设置链接优先级

randomize=false

randomize=false 能够设置优先链接放在第一位的 servercode

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 的说明:

https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.1/html/Fault_Tolerant_Messaging/files/FMQFaultTolStaticFailover.html

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

相关文章
相关标签/搜索