Java-Interview-Advanced/docs/distributed-system/eventual-consistency.md

9 lines
774 B
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

其实也很简单自己写一个可靠消息服务即可接收人家发送的half message然后返回响应给人家如果Producer没收到响应则重发。然后Producer执行本地事务接着发送commit/rollback给可靠消息服务。
可靠消息服务启动一个后台线程定时扫描本地数据库表中所有half message超过一定时间没commit/rollback就回调Producer接口确认本地事务是否成功获取commit/rollback
如果消息被rollback就废弃掉如果消息被commit就发送这个消息给下游服务或者是发送给RabbitMQ/Kafka/ActiveMQ都可以然后下游服务消费了必须回调可靠消息服务接口进行ack
如果一段时间都没收到ack则重发消息给下游服务