FolkMQ v1.7.8

FolkMQ v1.2 更新与兼容说明

本次版本发布,增加了"事务消息"、"消息属性" 的支持。

兼容说明

  • 本次更新,向下兼容。
  • 新增的功能功能(事务消息,发送与监听模式模式,消息属性),需要新版服务端和客户端支持。

更新说明

  • 添加 协议版本的握手传递
  • 添加 消息事务支持(即二段式提交),支持反向事务确认
  • 添加 消息用户属性支持
  • 优化 内存占用与快照大小
  • 优化 安全停止延时改为4秒
  • 优化 客户端相关参数校验
  • 优化 客户端的心跳间隔为6秒
  • 优化 停止打印信息

新功能示例(事务消息):

//准备(1.取名字;2.添加事务回查)
MqClient client = FolkMQ.createClient("folkmq://127.0.0.1:18602")
    .nameAs("demoapp") //一般用当前应用名
    .connect();

//用于服务端发起的事务回查
client.transactionCheckback(m->{
  if (m.isTransaction()) {
      //极端特殊的情况下,客户端未完成事务确认。由服务端发起补尝确认
      if("1".equals(m.getAttr("orderId"))) {
          //一般这里,需要查询数据库之类的
          m.acknowledge(true);
      }
  }
});
    
//发送事务消息    
MqTransaction tran = client.newTransaction();

try {
    client.publish("demo.topic", new MqMessage("demo1").attr("orderId","1").transaction(tran));
    client.publish("demo.topic", new MqMessage("demo2").attr("orderId","1").transaction(tran));
    client.publish("demo.topic", new MqMessage("demo3").attr("orderId","1").transaction(tran));
    client.publish("demo.topic", new MqMessage("demo4").attr("orderId","1").transaction(tran));

    tran.commit();
} catch (Throwable e) {
    tran.rollback();
}