Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Cloud Alibaba 对接 RocketMQ 5.0 讨论 #2843

Closed
steverao opened this issue Oct 14, 2022 · 4 comments
Closed

Spring Cloud Alibaba 对接 RocketMQ 5.0 讨论 #2843

steverao opened this issue Oct 14, 2022 · 4 comments
Labels

Comments

@steverao
Copy link
Collaborator

RocketMQ 5.0 新版特性

RocketMQ 5.0 作为一个大版本,带了很多新特性,相关特性总览如下图所示:
image

  • 基础架构云原生化

image

主要是将 Broker 职责进行拆分,拆分出了 Proxy,对客户端影响较小。

  • 轻量 API 和多语言集成
    RocketMQ 5.0 推出了基于 gRPC 全新的多语言 SDK,新的 SDK 化繁为简,更轻量级,也更容易被使用和集成。
    在 5.0 版本中,官方推荐的 Java Client 的 maven 坐标为:
<dependency>
        <groupId>org.apache.rocketmq</groupId>
        <artifactId>rocketmq-client-java</artifactId>
        <version>5.0.0</version>
</dependency>

而在 4.9 版本中,maven 坐标为:

<dependency>
        <groupId>org.apache.rocketmq</groupId>
        <artifactId>rocketmq-client</artifactId>
        <version>4.9.4</version>
</dependency>

在 RocketMQ 5.0 中,为了统一所有语言的客户端,单独维护了一个 Github 仓库https://github.com/apache/rocketmq-clients 用于开发多语言客户端,其中包括了 Java,Golang,Cpp、Rust 等语言。
而在 RocketMQ 4.x 版本中,Java 语言还是用的 RocketMQ 主仓库中的 client 模块作为 client。也就是说在 RocketMQ 5.0 中,Java 客户端发生了非常巨大的变化,达到了化繁为简,轻量级,与其他语言功能统一的目的。
那么在 Spring Cloud Alibaba 中,我们也会考虑使用新版的 Java Client 作为底层实现,对相关代码进行更新。

Consumer

新版的 Java Client 中,提供了三种 Consumer 类型。其中 SimpleConsumer 是新添加的消费者接口,提供了更灵活的自定义配置。
可以考虑在 Spring Cloud Alibaba 中,接入最新版的 Java Client,并支持相应的 Consumer 类型。
具体可以参考https://rocketmq.apache.org/zh/docs/%E5%8A%9F%E8%83%BD%E8%A1%8C%E4%B8%BA/06consumertype

Producer

相应的,Producer 的接口也发生了改变。
Producer 的实现,也可以根据最新的接口,做出相应的修改。

  • 事件、流处理场景集成
    在计算框架方面,RocketMQ 5.0 引入了一套轻量级流式处理框架 RSteams。RStreams 依赖少、部署简单,可任意横向扩展,利用 RocketMQ 资源即可完成轻量级的数据处理和计算。
    Github: https://github.com/apache/rocketmq-streams
    rocketmq-stream 实现了一系列高级的API,可以让用户很方便的编写流计算的程序,实现自己的业务需求。

我们知道 Spring Cloud Alibaba 中通过 Spring Cloud Stream 来集成 RocketMQ,这里我们可以考虑创建一个新的 binder,对 rocketmq-streams 也进行集成。具体的集成可以参考 Spring Cloud Stream 官方对 kafka-streams 的集成。
image

参考:https://github.com/spring-cloud/spring-cloud-stream#apache-kafka-streams-binder

待处理

  1. Provider 客户端升级方案需要进一步确定。
  2. Consumer 客户端支持 SimpleConsumer 方案需要进一步确定。
  3. rocketmq-streams 是否支持流时间处理以及支持的形式需要在兴趣小组和社区核心内部讨论。
@steverao steverao added the kind/discussion Mark as discussion issues/pr label Oct 14, 2022
@LeBW
Copy link
Contributor

LeBW commented Mar 31, 2023

背景

RocketMQ 5.0 发布了全新的多语言 SDK,其中也包括全新的 Java SDK。

根据阿里云官网文档,RocketMQ 5.x 系列 SDK 将作为后续主力研发版本,将完全适配 RocketMQ 5.x 服务端,因此推荐新用户使用 5.x 系列 SDK。

在这里,我对目前两个版本 SDK 的特点做了总结和对比,如下表所示

Feature 5.x SDK 4.x SDK
生产者发送普通消息
生产者发送顺序消息
生产者发送定时/延时消息 ✅(支持任意时间定时) ❌(只支持分级延时)
生产者发送事务消息
废弃生产者组(ProducerGroup)
支持 Push Consumer
支持 Pull Consumer
支持 Simple Consumer
消费者组消费位点初始值更明确
支持丰富监控指标/Trace数据

此外,还有一些使用上的区别,例如 异步接口全面 Future 化、引入不变形全面使用 builder 模式 等,均会在代码层面进行适配。

可以看到, 5.x SDK 已经有了一些 4.x SDK 不具备的功能。并且,后续 RocketMQ 5.x 服务端的新功能,都会在 5.x SDK 中进行适配,而 4.x SDK 仅作存量客户维护使用,因此往后两个版本的 SDK 差距会越来越大,这也是为什么我们需要使用 5.x SDK 对 Spring Cloud Alibaba 进行重构的原因。

Spring Cloud Alibaba 支持 RocketMQ 5.0

Spring Cloud Alibaba 中,目前集成的是 RocketMQ 4.x SDK,具体版本为 4.9.4,

从消息类型的角度上来看,目前支持以下功能:

  • 发送/接受普通消息
  • 发送/接受顺序消息
  • 发送/接受事务消息
  • 发送/接受延时消息(不支持定时消息)

从消费模式的角度来看,支持两种消费模式:

  • 订阅消费(利用 RocketMQ 中 PushConsumer 来实现)
  • 轮询消费(利用 RocketMQ 中 PullConsumer 来实现)

在重构并使用 5.x SDK 后,

从消息类型的角度来看,将支持以下功能:

  • 发送/接受普通消息
  • 发送/接受顺序消息
  • 发送/接受事务消息
  • 发送/接受延时消息、定时消息

从消费者的角度来看,仍然将支持订阅以及轮询消费模式,其中轮询模式将使用 5.x 中新添加的 SimpleConsumer 进行实现。

同时,还将支持日后 5.x SDK 推出的新功能。

支持方式

RocketMQ Binder 核心类 RocketMQMessageChannelBinder实现了 Spring Cloud Stream 规范,内部会构建 RocketMQInboundChannelAdapterRocketMQProducerMessageHandler

  • RocketMQProducerMessageHandler 会基于 Binding 配置通过 RocketMQProduceFactory 构造 RocketMQ 中的 Producer 对象,其内部会把 spring-messaging 模块内 org.springframework.messaging.Message消息类转换成 RocketMQ 的消息类 org.apache.rocketmq.common.message.Message,然后发送出去。
  • RocketMQInboundChannelAdapter 会基于 Binding 配置通过 RocketMQConsumerFactory 构造 RocketMQ 中的 consumer 对象,其内部会启动 RocketMQ Consumer 接收消息。

支持的方式,只需从上述两个关键类开始重构,内部实现由老版本 SDK 中的生产者和消费者换成新版本 SDK 中的生产者和消费者,然后做必要的兼容性即可。

另外,由于两个版本 SDK 提供的配置(例如生产者、消费者配置等)格式不同,需要对现有的配置项进行重新适配。

重构完毕后,需要提供相应的单元测试,保证所有功能正常运转。

可能引入的问题

  • 5.x SDK 仅支持 5.x 系列服务端,不兼容 4.x 系列服务端。

因此考虑在较新的 Spring Cloud Alibaba 版本上升级 SDK,避免对存量老用户产生影响。

另外,如果用户确实想要在使用新版 Spring Cloud Alibaba 的基础上,使用老版本的 rocketmq-starter 以连接 RocketMQ 4.x 版本,也可以通过单独指定 rocketmq-starter 的版本来实现,因此可以理解为升级 SCA 版本带来的 RocketMQ 兼容性问题并不是完全无法解决的。

@zuowenzhi
Copy link

spring cloud stream rocketmq 可以实现连接多个数据源吗

Copy link

This issue has been open 30 days with no activity. This will be closed in 7 days.

@github-actions github-actions bot added the stale label Apr 12, 2024
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity.If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the Sping Cloud Alibaba Community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants