MemoryMQ 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MemoryMQ --version 1.0.0                
NuGet\Install-Package MemoryMQ -Version 1.0.0                
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="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MemoryMQ --version 1.0.0                
#r "nuget: MemoryMQ, 1.0.0"                
#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=1.0.0

// Install MemoryMQ as a Cake Tool
#tool nuget:?package=MemoryMQ&version=1.0.0                

MemoryMQ

介绍

基于内存(System.Threading.Channels)的消息队列,主要适用的目标是一些非常简单的单体项目,不希望引入RabbitMQ等依赖的同时又希望有一个消息队列,支持功能:

  1. 失败重试(固定间隔、递增间隔、指数间隔)
  2. 消息持久化
  3. 控制每个消费者的并发数

使用方式

支持.NET 6及以上项目,使用方式:

  1. 引入依赖库
  2. 注册服务及消费者
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>();
  1. 配置消费者

// 实现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 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.

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.4.1 268 11/24/2023
1.4.0 219 8/9/2023
1.3.0 178 8/9/2023
1.2.1 140 11/24/2023
1.2.0 176 7/29/2023
1.1.4 202 7/24/2023
1.1.1 198 7/21/2023 1.1.1 is deprecated because it has critical bugs.
1.1.0 177 7/14/2023
1.0.1 164 7/13/2023
1.0.0 166 7/10/2023
0.0.2 201 7/9/2023
0.0.1 162 7/8/2023