cn-rmq 1.0.1 发布 基于可靠消息的分布式事务解决方案

  

RMQ(reliable-message-queue)是基于可靠消息的分布式事务解决方案。

中文文档

RMQ对接示例:

框架定位

  • RMQ本身不生产消息队列,只是消息的搬运工。
  • RMQ框架提供消息预发送、消息发送、消息确认、消息恢复、消息管理等功能,结合成熟的消息中间件,解决分布式事务,达到数据最终一致性。

业务系统对接RMQ

详细对接说明请查看《快速入门》和《对接示例说明

maven依赖

在业务系统的pom文件中引入rmq-api最新版本依赖:

# 中央仓库: https://search.maven.org/search?q=rmq-api
<dependency>
  <groupId>com.gitee.nuliing</groupId>
  <artifactId>rmq-api</artifactId>
  <version>${最新稳定版本}</version>
</dependency>

在业务代码中引入RMQ的Dubbo服务

import org.apache.dubbo.config.annotation.Reference;
import com.cn.rmq.api.service.IRmqService;

@Reference
private IRmqService rmqService;

编写消息发送方业务方法

public void doBusiness() {
        // 自定义消息队列名称
        String queue = "test.queue";
        // 消息内容, 如果传输对象,建议转换成json字符串
        String messageContent = "......";

        // 调用RMQ,预发送消息
        String messageId = rmqService.createPreMessage(queue, messageContent);

        // 执行业务
        ...
        ...

        // 异步调用RMQ,确认发送消息
        RpcContext.getContext().asyncCall(() -> rmqService.confirmAndSendMessage(messageId));
    }

编写消息消费方业务方法

public void handleMsg(RmqMessage msg) {
        try {
            String messageContent = msg.getMessageBody();

            // 执行业务
            ...
            ...

            // 通知RMQ消息消费成功
            // 如果使用的是RMQ的directSendMessage,则无需通知
            if (StringUtils.isNotBlank(msg.getMessageId())) {
                rmqService.deleteMessageById(msg.getMessageId());
            }
        } catch (Exception e) {
            ...
        }
    }

猜你喜欢

转载自www.oschina.net/news/106675/cn-rmq-1-0-1-released