7le / shine-mq Goto Github PK
View Code? Open in Web Editor NEWReliable message distributed transaction middleware(可靠消息分布式事务中间件) ✨
License: Apache License 2.0
Reliable message distributed transaction middleware(可靠消息分布式事务中间件) ✨
License: Apache License 2.0
消息的可靠发送可以认为是尽最大努力发送消息通知,有两种实现方法:
在shine-mq
已经做了两种实现方法共性的消息持久化工作,默认实现的持久消息数据库是redis
,也可以自己实现Coordinator
接口(自行实现的需要注入到spring容器)。而捞起的超时异常消息,要怎么处理就需要根据业务自行选择是否要回查。
另外这个定时任务是需要自己实现的,具体如何实现可以自由发挥了(例如可以在服务A里实现定时任务,或者有统一的daemon
来做处理)。
如果redis挂了,持久化会丢最多1秒的数据,那么这部分异常的消息怎么处理?
在shine-mq
使用分布式事务的时候会默认创建死信队列,死信队列的配置如下:
public static final String DEAD_LETTER_QUEUE = "dead_letter_queue";
public static final String DEAD_LETTER_EXCHANGE = "dead_letter_exchange";
public static final String DEAD_LETTER_ROUTEKEY = "dead_letter_routekey";
当服务B接收mq的消息失败次数大于receiveMaxRetries
(默认为3,可以配置),就会将失败的消息投递到死信队列。死信队列的消息同样是可以进行消费,而如何来处理就是各自按着业务来实现了。
@Autowired
RabbitmqFactory factory;
@PostConstruct
public void test() {
//配置死信队列 失败时候处理
factory.add(MqConstant.DEAD_LETTER_QUEUE, MqConstant.DEAD_LETTER_EXCHANGE,
MqConstant.DEAD_LETTER_ROUTEKEY, new ProcessorException(), SendTypeEnum.DLX);
}
/**
* 处理异常消息
*/
static class ProcessorException extends BaseProcessor {
@Override
public Object process(Object msg, Message message, Channel channel) {
System.out.println("自行实现 通知人工处理 或者回调原服务A的回滚接口:" + msg);
return null;
}
}
因为就实现了一条死信队列,多个分布式事务失败的消息都会被同一个死信队列的processor
消费,这里可以根据Message
获取对应原始的队列信息来区分处理。
发送ready消息的时候,ready消息发送成功,但是此时因为特殊原因,调用方业务回滚了(比如说宕机),那么ready消息被下游服务消费了,但是实际上上游服务是没成功的,不就有问题了吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.