MemoryMQ 0.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MemoryMQ --version 0.0.1
NuGet\Install-Package MemoryMQ -Version 0.0.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="MemoryMQ" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MemoryMQ --version 0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MemoryMQ, 0.0.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.
// Install MemoryMQ as a Cake Addin #addin nuget:?package=MemoryMQ&version=0.0.1 // Install MemoryMQ as a Cake Tool #tool nuget:?package=MemoryMQ&version=0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MemoryMQ
介绍
基于内存(System.Threading.Channels
)的消息队列,主要适用的目标是一些非常简单的单体项目,不希望引入RabbitMQ等依赖的同时又希望有一个消息队列,支持功能:
- 失败重试(固定间隔、递增间隔、指数间隔)
- 消息持久化
- 控制每个消费者的并发数
使用方式
支持.NET 6及以上项目,使用方式:
- 引入依赖库
- 注册服务及消费者
builder.Services.AddMemoryMQ(it =>
{
// 是否开启持久化 目前仅支持Sqlite
it.EnablePersistent = true;
// 重试策略
it.RetryMode = RetryMode.Incremental;
// 重试间隔
it.RetryInterval = TimeSpan.FromSeconds(5);
});
// 添加消费者,注意用Scoped生命周期
builder.Services.AddScoped<ConsumerA>();
builder.Services.AddScoped<ConsumerB>();
- 配置消费者
// 实现IMessageConsumer接口
public class ConsumerA : IMessageConsumer
{
private readonly ILogger<ConsumerA> _logger;
public ConsumerA(ILogger<ConsumerA> logger)
{
_logger = logger;
}
public MessageOptions Config { get; } = new MessageOptions()
{
Topic = "topic-a",
ParallelNum = 5,
RetryCount = 3
};
public Task ReceivedAsync(IMessage message, CancellationToken cancellationToken)
{
_logger.LogInformation("received {MessageBody} {Now}", message.Body, DateTime.Now);
return Task.CompletedTask;
}
public Task FailureRetryAsync(IMessage message, CancellationToken cancellationToken)
{
_logger.LogInformation("retry max times {RetryTimes} {MessageBody} {Now}",message.GetRetryCount(), message.Body, DateTime.Now);
return Task.CompletedTask;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- Microsoft.Extensions.Options (>= 7.0.1)
- System.Data.SQLite (>= 1.0.118)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.