RedMQ
基于redis的消息队列
优点:
消息不丢失
消息不重复
分布式缓存锁
在线安全关闭消费队列(防消息丢失)
在线查看未处理消息数
在线查看消费线程数
在线注册topic和group
提供restfulAPI
实时监控/报警
缺点:
重度依赖redis
Example
首先需要在线或者调用api注册topic和group,未注册的topic和group无法发送和接收消息
支持P2P,Publish/Subscribe
发送消息
String topicName = "testTopic";
//groupName为空时,消息发送给topic下注册的所有消费者分组,
//groupName不为空,消息只发送给对应的group分组
String groupName = "testGroup";
DefaultProducer defaultProducer = new DefaultProducer(topicName, groupName);
for(int i=0;i<100000;i++) {
String message = "i am message " + i;
defaultProducer.sendMessage(message);
}
处理消息
//同一个分组无法重复消息同一条消息,依赖redis的list实现
String topicName = "testTopic";
String groupName = "testGroup";
//可控制消费者线程数,默认单线程处理消息,可分布式部署多个节点处理消息
DefaultConsumer defaultConsumer = new DefaultConsumer(topicName, groupName, 2);
defaultConsumer.setMessageLinser(new MessageLinser() {
@Override
public MessageStatus consumeMessage(String message) {
System.out.println(message);
return MessageStatus.SUCCESS;
}
});
defaultConsumer.start();
接口文档地址
http://localhost:8000/doc.html

在线管理地址
查看消息队列,安全关闭消费者分组

在线查看、注册消息主题

在线查看、注册消费者分组

github地址:https://github.com/will-xlz/RedMQ
网友评论