Galosys.Foundation.NewLife.RocketMQ
26.10.29.1
dotnet add package Galosys.Foundation.NewLife.RocketMQ --version 26.10.29.1
NuGet\Install-Package Galosys.Foundation.NewLife.RocketMQ -Version 26.10.29.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.NewLife.RocketMQ" Version="26.10.29.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.NewLife.RocketMQ" Version="26.10.29.1" />
<PackageReference Include="Galosys.Foundation.NewLife.RocketMQ" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.NewLife.RocketMQ --version 26.10.29.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.NewLife.RocketMQ, 26.10.29.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.NewLife.RocketMQ@26.10.29.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.NewLife.RocketMQ&version=26.10.29.1
#tool nuget:?package=Galosys.Foundation.NewLife.RocketMQ&version=26.10.29.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.NewLife.RocketMQ
成熟度: 🟡 预览 — 基于 NewLife.RocketMQ 3.0,核心功能完成
基于 NewLife.RocketMQ 的 RocketMQ 客户端实现,支持 Remoting + gRPC 双协议,兼容 RocketMQ 4.x 和 5.x。
为什么选择 NewLife 实现
| 特性 | Apache rocketmq.client 5.x | NewLife.RocketMQ |
|---|---|---|
| 协议 | gRPC(仅 5.x Proxy) | Remoting + gRPC(双协议) |
| 兼容 4.x | ❌ | ✅ |
| 兼容 5.x | ✅ | ✅ |
| NuGet 维护 | 缓慢(最新 5.1.0, 2023.3) | 活跃(2026.3) |
| 延迟消息 | DeliveryTimestamp | 18 级预设延迟 |
安装
<PackageReference Include="Galosys.Foundation.NewLife.RocketMQ" Version="x.x.x" />
快速开始
1. 最小配置
{
"RocketMQ": {
"Endpoints": "localhost:9876"
}
}
NewLife 实现连接 NameServer(默认 9876),与 Apache 实现连接 Proxy(5.2+ 默认 8080,≤5.1 为 8081)不同。
2. 注册服务
services.AddNewLifeRocketMQ(configuration);
3. 发送消息
发送侧无泛型约束,支持任意 POCO 类型:
using Galosys.Foundation.RocketMQ.Abstractions;
public class OrderCreatedEvent
{
public string OrderNo { get; set; }
}
public class OrderService
{
private readonly RmqTemplate _template;
public OrderService(RmqTemplate template) => _template = template;
public async Task SendAsync() =>
await _template.SendAsync("order_created", new OrderCreatedEvent { OrderNo = "ORD001" });
public async Task SendDelayAsync() =>
await _template.SendAsync("order_created", new OrderCreatedEvent { OrderNo = "ORD001" }, delaySeconds: 30);
}
延迟消息自动映射到 RocketMQ 18 级预设延迟等级(1s/5s/10s/30s/1m/2m/.../2h)。
4. 消费消息
using Galosys.Foundation.RocketMQ.Abstractions;
[Handler]
public class OrderHandler : IMessageHandler<OrderCreatedMessage>
{
[RmqHandler("order_created")]
public Task<bool> HandleAsync(OrderCreatedMessage msg) => Task.FromResult(true);
}
完整配置
{
"RocketMQ": {
"Endpoints": "localhost:9876",
"AccessKey": null,
"SecretKey": null,
"ConsumerGroup": "my_service",
"Handlers": {
"order_created": {
"PrefetchCount": 16,
"Concurrency": 4,
"MaxRetryCount": 3,
"RetryBaseDelayMs": 1000
}
}
}
}
详细配置说明参见 Abstractions README。
实现细节
| 组件 | 说明 |
|---|---|
NewLifeRmqPublisher |
基于 NewLife.RocketMQ.Producer,按 Topic 缓存,延迟消息映射 DelayTimeLevels |
NewLifeRmqConsumer |
基于 NewLife.RocketMQ.Consumer,OnConsume 回调,SemaphoreSlim 并发控制 |
NewLifeRmqTemplate |
组合 Publisher + Consumer 的统一门面 |
NewLifeRmqBootstrapper |
IHostedLifecycleService,启动时扫描 [RmqHandler],关闭时释放资源 |
NewLifeRmqHealthCheck |
检查 Endpoints 配置是否有效 |
NewLifeRmqTracing |
OTel ActivitySource,Span 带 Topic/Tag/ConsumerGroup 标签 |
NewLifeRmqMeter |
6 个 Counter/Histogram 指标 |
切换实现
从 Apache 实现切换到 NewLife 实现,业务代码无需任何修改:
<PackageReference Include="Galosys.Foundation.RocketMQ.Client" Version="x.x.x" />
<PackageReference Include="Galosys.Foundation.NewLife.RocketMQ" Version="x.x.x" />
同时将 Endpoints 从 Proxy 地址(如 localhost:8080)改为 NameServer 地址(如 localhost:9876)。
依赖
Galosys.Foundation.RocketMQ.AbstractionsNewLife.RocketMQ3.0(含NewLife.Core)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Galosys.Foundation.RocketMQ.Abstractions (>= 26.10.29.1)
- newlife.rocketmq (>= 3.0.2026.305)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.10.29.1 | 115 | 10/29/2026 |
| 26.10.20.1 | 110 | 10/20/2026 |
| 26.10.16.2 | 109 | 10/16/2026 |
| 26.10.16.1 | 110 | 10/16/2026 |
| 26.10.9.1 | 105 | 10/9/2026 |
| 26.10.8.1 | 104 | 10/8/2026 |
| 26.9.23.1 | 121 | 9/23/2026 |
| 26.9.16.1 | 125 | 9/16/2026 |
| 26.9.15.1 | 112 | 9/15/2026 |
| 26.9.14.1 | 125 | 9/15/2026 |
| 26.8.29.1 | 128 | 8/31/2026 |
| 26.8.26.1 | 134 | 8/26/2026 |
| 26.8.23.1 | 135 | 8/23/2026 |
| 26.8.21.1 | 124 | 8/21/2026 |
| 26.8.20.1 | 132 | 8/20/2026 |
| 26.8.18.1 | 129 | 8/18/2026 |
| 26.8.17.1 | 131 | 8/17/2026 |
| 26.8.13.2 | 149 | 8/13/2026 |
| 26.8.13.1 | 135 | 8/13/2026 |
| 26.8.12.2 | 132 | 8/12/2026 |
Loading failed