当前位置:网站首页>ActiveMQ -- message retry mechanism
ActiveMQ -- message retry mechanism
2022-07-25 09:18:00 【Why don't you laugh】
Message retry mechanism
Under what circumstances will it cause message resending
- Consumers use transactions And in session Called in rollback
- Consumers use transactions And calling commit Previously closed or not commit
- Consumer end in SESSION_ACKNOWLEDGE In the delivery mode of , stay session Called in recover
Message retransmission interval and number of retransmissions
- The time interval :1
- Number of retransmissions :6
Toxic news
Poison ACKA message was redelivedred Exceeds the default maximum number of repetitions ( Default 6 Time ) when , The consumer will give MQ Send a “Posion ACK”, The news is poisonous , notice broker Don't send it again . Now broker I'll put this message in DLQ( Dead letter queue ).
Attribute specification
collisionAvoidanceFactor: Set the positive and negative percentage of the conflict prevention range , Only enable useCollisionAvoidance Parameter . That is to add a time fluctuation range to the delay time . The default value is 0.15.
maximumRedeliveries: Maximum number of retransmissions , Throw an exception after reaching the maximum number of retransmissions . by -1 There is no limit to the number of times , by 0 It means no retransmission . The default value is 6.
maximumRedeliveryDealy: Maximum transmission delay , Only in useExponentialBackOff by true Effective when (V5.5). Suppose the first reconnection interval is 10ms, The multiple is 2, So the second reconnection interval is 20ms, The third time is 40ms, When the reconnection interval is larger than the maximum reconnection interval , After each reconnection interval is the maximum reconnection interval .
initialRedeliveryDelay: Initial retransmission delay time , Default 1000L
redeliveryDelay: Retransmission delay time , When initialRedeliveryDelay=0 Effective when , Default 1000L
useCollissionAvoidance: Enable anti-collision , Default false
useExponentialBackOff: Enable exponential multiple increment to increase delay time , Default false
backOffMultiplier: The reconnection interval increases , Only values greater than 1 And enable useExponentialBackOff Parameter takes effect . Default 5
verification
- Start the transaction on the consumer side
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
# Do not commit transactions
// session.commit()
The producer produces a message , Start consumer
Don't use it on the consumer side
MessageListenerMonitor the way to test
1. Start consumers for the first time , Will consume normally once
2. Then start up 6 Secondary consumer , Will consume data ( Default 6 Time )
3. The first 7 Time , No message consumption
In the 7 Next time , The message is marked as toxic , Will enter DLQ, Dead letter queue

Related configuration
If you don't want to try again 6 Next time , Then mark the message as toxic , Can be configured as 3 Time :topicPolicy.setMaximumRedeliveries(3)
For other configurations, please refer to the official website as follows :
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);
springboot Configure retry mechanism
@Component
@EnableJms
public class ActivemqConfig {
//.....
@Bean
public RedeliveryPolicy redeliveryPolicy(){
RedeliveryPolicy redeliveryPolicy= new RedeliveryPolicy();
// Whether after every attempt to resend failed , Increase the waiting time
redeliveryPolicy.setUseExponentialBackOff(true);
// Number of retransmissions , The default is 6 Time I'm going to set it to 10 Time
redeliveryPolicy.setMaximumRedeliveries(10);
// retransmit interval , The default is 1 second
redeliveryPolicy.setInitialRedeliveryDelay(1);
// Wait after the first failure before resending 500 millisecond , The second failure and wait 500 * 2 millisecond , there 2 Namely value
redeliveryPolicy.setBackOffMultiplier(2);
// Whether to avoid message collision
redeliveryPolicy.setUseCollisionAvoidance(false);
// Set the maximum delay time for retransmission -1 There is no delay, only UseExponentialBackOff(true) by true Effective when
redeliveryPolicy.setMaximumRedeliveryDelay(-1);
return redeliveryPolicy;
}
}
边栏推荐
- centos更改mysql数据库目录
- 超赞的yolo目标检测训练所用垃圾分类数据集共享——标注好的约3000张
- Comparison between symmetric encryption and asymmetric encryption
- Oracle10g单实例数据库升级到哪个版本好,求建议
- The hole of scroll view in uniapp
- The development of art NFT
- How to use pixi.js to make simple Parkour games
- activemq--可持久化机制之AMQ
- What are the commands used by pl/sql tools to export SQL files?
- Shell脚本
猜你喜欢

Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL

A picture to quickly understand envoyfilter in istio

为什么说DAO是未来的公司形式

Comparison between symmetric encryption and asymmetric encryption

What version of Oracle10g single instance database is better to upgrade to? Ask for suggestions

【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

51 single chip microcomputer key control LED light status

Do you know these methods of MySQL database optimization?
![[buuctf-n1book][Chapter 2 advanced web]ssrf training](/img/29/8894d04b27e0e73c4458c27bd9b935.png)
[buuctf-n1book][Chapter 2 advanced web]ssrf training

How to realize the drop-down option box of wechat applet
随机推荐
Network principle (2) -- network development
Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?
PL/SQL工具导出sql文件所使用的命令是什么?
Anti shake and throttling
What version of Oracle10g single instance database is better to upgrade to? Ask for suggestions
centos更改mysql数据库目录
音乐人的 NFT 指南
yarn : 无法加载文件 yarn.ps1,因为在此系统上禁止运行脚本。
整理 华为AP-3010DN_V2配置创建wifi
Django4.0 + web + MySQL 5.7 realize simple login operation
Bi business interview with data center and business intelligence (I): preparation for Industry and business research
[arm] Xintang nuc977 transplants wk2124 drive
How to connect tdengine with idea database tool?
How to write the code of wechat applet implementation tab
Algorithm --- flip digit (kotlin)
[deep learning] mask Dino Trilogy - the correct way to open Detr Pandora's box
Collection of common algorithm questions in test post interview
Troubleshooting error: NPM install emojis list failed
activemq--延迟投递和定时投递
js弹出式城市筛选组件匹配手机移动端