环境:MAC OS X 10.11.5 + ActiveMQ 5.13.3
1. 参数说明
(1)collisionAvoidanceFactor 默认值 0.15,The percentage of range of collision avoidance if enabled
(2)maximumRedeliveries 默认值 6,消息被认为是“毒丸”之前的最大重发次数。一旦企图超过该重试次数,将被认为是“毒丸”,并发送到 DLQ。设置为 -1,表明无限次重发。
(3)maximumRedeliveryDelay 默认值 -1,下次重发时的延迟等待时间。设置为 -1,表示没有最大延迟等待时间限制。Sets the maximum delivery delay that will be applied if the useExponentialBackOff option is set.
(4)initialRedeliveryDelay 默认值 1000L,第一次重发的延迟等待时间。
(5)redeliveryDelay 默认值 1000L,每次重发的重发的延迟等待时间。
(6)useCollisionAvoidance 默认值 false,Should the redelivery policy use collision avoidance
(7)useExponentialBackOff 默认值 false,Should exponential back-off be used (i.e. to exponentially increase the timeout)
(8)backOffMultiplier 默认值 5,The back-off multiplier
2. 客户端重写重发策略
2.1 Connection 级别重写
(1)作为参数写在 Connection URI 中,比如:
tcp://localhost:61616?jms.prefetchPolicy.all=100&jms.redeliveryPolicy.maximumRedeliveries=5
(2)纯代码实现
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(500);
policy.setBackOffMultiplier(2);
policy.setUseExponentialBackOff(true);
policy.setMaximumRedeliveries(2);
2. 2 Destination 级别重写
ActiveMQConnection connection ... // Create a connection
RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
queuePolicy.setInitialRedeliveryDelay(0);
queuePolicy.setRedeliveryDelay(1000);
queuePolicy.setUseExponentialBackOff(false);
queuePolicy.setMaximumRedeliveries(2);
RedeliveryPolicy topicPolicy = new RedeliveryPolicy();
topicPolicy.setInitialRedeliveryDelay(0);
topicPolicy.setRedeliveryDelay(1000);
topicPolicy.setUseExponentialBackOff(false);
topicPolicy.setMaximumRedeliveries(3);
// Receive a message with the JMS API
RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap();
map.put(new ActiveMQTopic(">"), topicPolicy);
map.put(new ActiveMQQueue(">"), queuePolicy);
参考文献:
1. http://activemq.apache.org/redelivery-policy.html
1. 参数说明
(1)collisionAvoidanceFactor 默认值 0.15,The percentage of range of collision avoidance if enabled
(2)maximumRedeliveries 默认值 6,消息被认为是“毒丸”之前的最大重发次数。一旦企图超过该重试次数,将被认为是“毒丸”,并发送到 DLQ。设置为 -1,表明无限次重发。
(3)maximumRedeliveryDelay 默认值 -1,下次重发时的延迟等待时间。设置为 -1,表示没有最大延迟等待时间限制。Sets the maximum delivery delay that will be applied if the useExponentialBackOff option is set.
(4)initialRedeliveryDelay 默认值 1000L,第一次重发的延迟等待时间。
(5)redeliveryDelay 默认值 1000L,每次重发的重发的延迟等待时间。
(6)useCollisionAvoidance 默认值 false,Should the redelivery policy use collision avoidance
(7)useExponentialBackOff 默认值 false,Should exponential back-off be used (i.e. to exponentially increase the timeout)
(8)backOffMultiplier 默认值 5,The back-off multiplier
2. 客户端重写重发策略
2.1 Connection 级别重写
(1)作为参数写在 Connection URI 中,比如:
tcp://localhost:61616?jms.prefetchPolicy.all=100&jms.redeliveryPolicy.maximumRedeliveries=5
(2)纯代码实现
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(500);
policy.setBackOffMultiplier(2);
policy.setUseExponentialBackOff(true);
policy.setMaximumRedeliveries(2);
2. 2 Destination 级别重写
ActiveMQConnection connection ... // Create a connection
RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
queuePolicy.setInitialRedeliveryDelay(0);
queuePolicy.setRedeliveryDelay(1000);
queuePolicy.setUseExponentialBackOff(false);
queuePolicy.setMaximumRedeliveries(2);
RedeliveryPolicy topicPolicy = new RedeliveryPolicy();
topicPolicy.setInitialRedeliveryDelay(0);
topicPolicy.setRedeliveryDelay(1000);
topicPolicy.setUseExponentialBackOff(false);
topicPolicy.setMaximumRedeliveries(3);
// Receive a message with the JMS API
RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap();
map.put(new ActiveMQTopic(">"), topicPolicy);
map.put(new ActiveMQQueue(">"), queuePolicy);
参考文献:
1. http://activemq.apache.org/redelivery-policy.html
没有评论:
发表评论