RocketMQ.NETClient
1.3.0-beta
This is a prerelease version of RocketMQ.NETClient.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RocketMQ.NETClient --version 1.3.0-beta
NuGet\Install-Package RocketMQ.NETClient -Version 1.3.0-beta
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="RocketMQ.NETClient" Version="1.3.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RocketMQ.NETClient --version 1.3.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RocketMQ.NETClient, 1.3.0-beta"
#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.
// Install RocketMQ.NETClient as a Cake Addin #addin nuget:?package=RocketMQ.NETClient&version=1.3.0-beta&prerelease // Install RocketMQ.NETClient as a Cake Tool #tool nuget:?package=RocketMQ.NETClient&version=1.3.0-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
rocketmq-client-dotnet
.NET客户端API
重构说明
代码逻辑说明
项目地址
ClementIV/rocketmq-client-dotnet
项目目录简介
.
├── rocketmq-client-dotnet RocketMQ .NET Client 文件
└── example
└── quickStart
├── ConsumerQuickStart PushConsumer Quick Start
├── ProducerQuickStart Producer Quick Start
└── PullConsumerQuickStart PullConsumer Quick Start
└── src
└── RocketMQ.NETClient NET Client
├── Consumer Consumer API
├── Interop 常量等
├── Message Message API
└── Producer Producer API
调试环境快速部署
TODO
API 对齐说明
功能 | C | .NET |
---|---|---|
同步消息发送 | Y | Y |
顺序消息发送 | Y | Y |
单向消息发送 | Y | Y |
拉取消息消费 | Y | Y |
推送消息消费 | Y | Y |
延时消息 | Y | Y |
消息压缩 | Y | Y |
消息过滤 | Y | Y |
字符串消息体 | Y | Y |
字节流消息体 | N | N |
Topic设置 | Y | Y |
Producer 创建说明
之前的方式
- 创建
DefaultProducerBuilder
对象producerBuilder
- 使用
producerBuilder
设置想要生成的producerBuilder
参数 - 调用
producerBuilder
中的Builder
函数返回一个IProducer
实例producer
- 使用
producer
示例代码:
//创建一个 producerBuilder
DefaultProducerBuilder producerBuilder = new DefaultProducerBuilder("group name",null,null);
//设置想要生成的 producerBuilder 参数
producerBuilder = producerBuilder.SetProducerNameServerAddress("127.0.0.1:9876");
//··· 其他的一些设置
// 函数返回一个 IProducer 实例 producer
IProducer producer = producerBuilder.Builder();
// 使用producer发送消息
producer.StartProducer();
var sendResult = producer.SendMessageSync(producer, messageIntPtr, out CSendResult sendResultStruct);
Console.WriteLine("send result:" + sendResult + ", msgId: " + sendResultStruct.msgId.ToString());
重构使用说明
- 创建producer对象(多种构造函数)
- 使用producer发送消息
//创建一个 producer
MQProducer producer = new MQProducer("GroupA", "127.0.0.1:9876");
producer.StartProducer();
// 创建一个消息 message
MQMessage message = new MQMessage("test");
// 使用producer发送消息
// SendMessageSync
var sendResult = producer.SendMessageSync(message);
Console.WriteLine("send result:" + sendResult + ", msgId: " + sendResult.MessageId);
对应Producer项目
PushConsumer使用说明(推荐使用)
使用说明
- 创建一个Push消费者
- 订阅一个
topic
- 注册回调函数
- 启动消费者
// 创建一个Push消费者
var consumer = new MQPushConsumer("xx", "127.0.0.1:9876");
Console.WriteLine($"consumer: {consumer}");
// 设置日志目录和级别
consumer.SetPushConsumerLogPath(".\\consumer_log.txt");
consumer.SetPushConsumerLogLevel(LogLevel.Trace);
// 获取消费者组号
var groupId = consumer.GetPushConsumerGroupID();
Console.WriteLine($"groupId: {groupId}");
// 订阅一个`topic`
consumer.Subscribe("test", "*");
//注册回调函数
consumer.RegisterMessageCallback(_callback);
//启动消费者
var result=consumer.StartPushConsumer();
Console.WriteLine($"start push consumer ptr: {result}");
对应项目
PullConsumer 使用说明
使用说明
- 创建一个PullConsumer
- 开启消费者
- 填充消息队列
- 主动拉取消费
//创建一个PullConsumer
MQPullConsumer consumer = new MQPullConsumer("xxx", "127.0.0.1:9876", ".\\log.txt", LogLevel.Trace);
//开启消费者
var result = consumer.StartPullConsumer();
Console.WriteLine($"start Pull consumer ? : {result}");
//填充消息队列
CMessageQueue[] msgs = consumer.FetchSubscriptionMessageQueues("test");
for (int j = 0; j < msgs.Length; j++)
{
int flag = 0;
Console.WriteLine("msg topic : " + new string(msgs[j].topic));
MessageQueue mq = new MessageQueue { topic = new string(msgs[j].topic), brokeName = new string(msgs[j].brokerName), queueId = msgs[j].queueId };
while (true)
{
try
{
//主动拉取消费
CPullResult cPullResult = consumer.Pull(mq,msgs[j], "", MQPullConsumer.getMessageQueueOffset(mq), 32);
Console.WriteLine(new string(msgs[j].topic) + " status : " + cPullResult.pullStatus +"Max offset "+ cPullResult.maxOffset + " offset: " + cPullResult.nextBeginOffset + " Quene Id" + msgs[j].queueId);
//Console.WriteLine(" " + msg.topic);
long a = cPullResult.nextBeginOffset;
MQPullConsumer.putMessageQueueOffset(mq, a);
switch (cPullResult.pullStatus)
{
case CPullStatus.E_FOUND:
break;
case CPullStatus.E_NO_MATCHED_MSG:
break;
case CPullStatus.E_NO_NEW_MSG:
flag = 1;
break;
case CPullStatus.E_OFFSET_ILLEGAL:
flag = 2;
break;
default:
break;
}
if(flag == 1|| cPullResult.nextBeginOffset == cPullResult.maxOffset)
{
break;
}
if (flag == 2)
{
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
项目地址
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.1
- Microsoft.Extensions.DiagnosticAdapter (>= 2.1.0)
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 |
---|---|---|
1.3.3-beta | 591 | 7/10/2019 |
1.3.2-beta | 413 | 7/10/2019 |
1.3.1-beta | 353 | 7/10/2019 |
1.3.0-beta | 572 | 7/10/2019 |
0.1.3-beta | 347 | 7/17/2019 |
0.1.0-beta | 388 | 7/16/2019 |
0.0.1-beta | 568 | 7/17/2019 |