序言
本文记录 rocketmq 事务消息的功能、使用、原理和应用场景。
一、官网文档摘要
什么是事务消息?
事务消息可以被看做一个支持最终一致性的两阶段提交的分布式系统。保证本地事务和发 metaq 消息作为原子操作。
使用限制
- 不支持定时和批量
- 检测次数限制:对 half message 的检查有 15 次的次数限制,可以修改 transactionCheckMax 参数。若 half message 被检测 transactionCheckMax 次后,则broker 打印日志并抛弃日志,可以实现 AbstractTransactionCheckListener 改变其行为。
- 检测超时时间:事务消息在 transactionTimeout 后被检测,该值在 broker 启动是设置,不过消息发送方可以设置 CHECK_IMMUNITY_TIME_IN_SECONDS 修改该值,且发送方优先级较高。
- 事务消息可能会被消费多次
(5) Committed message reput to the user’s target topic may fail. Currently, it depends on the log record. High availability is ensured by the high availability mechanism of RocketMQ itself. If you want to ensure that the transactional message isn’t lost and the transaction integrity is guaranteed, it is recommended to use synchronous double write. mechanism. (没理解)
(6) Producer IDs of transactional messages cannot be shared with producer IDs of other types of messages. Unlike other types of message, transactional messages allow backward queries. MQ Server query clients by their Producer IDs. (producer ID 不能共享,是不能机器之间共享吗?todo)
应用
事务状态
创建 producer
实现 TransactionListener 接口
