MemoryMQ 0.0.1

There is a newer version of this package available.
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
#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

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 234 11/24/2023
1.4.0 192 8/9/2023
1.3.0 166 8/9/2023
1.2.1 115 11/24/2023
1.2.0 150 7/29/2023
1.1.4 172 7/24/2023
1.1.1 176 7/21/2023
1.1.0 154 7/14/2023
1.0.1 138 7/13/2023
1.0.0 140 7/10/2023
0.0.2 171 7/9/2023
0.0.1 142 7/8/2023