SyZero.RabbitMQ 1.1.5-dev.1

This is a prerelease version of SyZero.RabbitMQ.
dotnet add package SyZero.RabbitMQ --version 1.1.5-dev.1
                    
NuGet\Install-Package SyZero.RabbitMQ -Version 1.1.5-dev.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="SyZero.RabbitMQ" Version="1.1.5-dev.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.RabbitMQ" Version="1.1.5-dev.1" />
                    
Directory.Packages.props
<PackageReference Include="SyZero.RabbitMQ" />
                    
Project file
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 SyZero.RabbitMQ --version 1.1.5-dev.1
                    
#r "nuget: SyZero.RabbitMQ, 1.1.5-dev.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 SyZero.RabbitMQ@1.1.5-dev.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=SyZero.RabbitMQ&version=1.1.5-dev.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SyZero.RabbitMQ&version=1.1.5-dev.1&prerelease
                    
Install as a Cake Tool

SyZero.RabbitMQ

SyZero 框架的 RabbitMQ 事件总线模块,提供分布式消息队列支持。

📦 安装

dotnet add package SyZero.RabbitMQ

✨ 特性

  • 🚀 事件总线 - 基于 RabbitMQ 的分布式事件总线
  • 💾 持久化 - 消息持久化保证可靠性
  • 🔄 自动重连 - 连接断开后自动重连
  • 📨 发布订阅 - 支持发布/订阅模式

🚀 快速开始

1. 配置 appsettings.json

{
  "RabbitMQ": {
    "HostName": "localhost",
    "Port": 5672,
    "UserName": "guest",
    "Password": "guest",
    "VirtualHost": "/",
    "ExchangeName": "my_exchange",
    "QueueName": "my_queue"
  }
}

2. 注册服务

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();

// 注册服务方式1 - 使用配置文件
builder.Services.AddRabbitMQEventBus();

// 注册服务方式2 - 使用委托配置
builder.Services.AddRabbitMQEventBus(options =>
{
    options.HostName = "localhost";
    options.Port = 5672;
    options.UserName = "guest";
    options.Password = "guest";
});

// 注册服务方式3 - 指定配置节
builder.Services.AddRabbitMQEventBus(builder.Configuration, "RabbitMQ");

var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();

3. 使用示例

// 定义事件
public class UserCreatedEvent : IEvent
{
    public long UserId { get; set; }
    public string UserName { get; set; }
}

// 发布事件
public class UserService
{
    private readonly IEventBus _eventBus;

    public UserService(IEventBus eventBus)
    {
        _eventBus = eventBus;
    }

    public async Task CreateUserAsync(User user)
    {
        // 创建用户后发布事件
        await _eventBus.PublishAsync(new UserCreatedEvent
        {
            UserId = user.Id,
            UserName = user.Name
        });
    }
}

// 订阅事件
public class UserCreatedEventHandler : IEventHandler<UserCreatedEvent>
{
    public async Task HandleAsync(UserCreatedEvent @event)
    {
        Console.WriteLine($"用户 {@event.UserName} 创建成功");
    }
}

📖 配置选项

属性 类型 默认值 说明
HostName string "localhost" RabbitMQ 主机地址
Port int 5672 端口号
UserName string "guest" 用户名
Password string "guest" 密码
VirtualHost string "/" 虚拟主机
ExchangeName string "" 交换机名称
QueueName string "" 队列名称
RetryCount int 5 重试次数

📖 API 说明

IEventBus 接口

方法 说明
PublishAsync<TEvent>(event) 发布事件
Subscribe<TEvent, THandler>() 订阅事件
Unsubscribe<TEvent, THandler>() 取消订阅

所有方法都有对应的异步版本(带 Async 后缀)


🔧 高级用法

延迟消息

await _eventBus.PublishAsync(new OrderTimeoutEvent
{
    OrderId = orderId
}, delay: TimeSpan.FromMinutes(30));

死信队列

builder.Services.AddRabbitMQEventBus(options =>
{
    options.DeadLetterExchange = "dead_letter_exchange";
    options.DeadLetterQueue = "dead_letter_queue";
});

⚠️ 注意事项

  1. 连接管理 - 应用会自动管理连接和重连
  2. 消息确认 - 默认使用手动确认模式
  3. 错误处理 - 处理失败的消息会进入死信队列

📄 许可证

MIT License - 详见 LICENSE

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.1.5-dev.1 23 1/29/2026
1.1.4 95 1/2/2026
1.1.4-dev.2 42 1/2/2026
1.1.4-dev.1 43 12/30/2025
1.1.3 95 12/30/2025
1.1.3-dev.6 45 12/30/2025
1.1.3-dev.3 114 1/19/2024
1.1.3-dev.2 169 11/3/2023
1.1.3-dev.1 189 3/21/2023
1.1.2 361 3/15/2023
1.1.2-dev.108.29344 186 3/15/2023
1.1.2-dev.108.28054 182 3/15/2023
1.1.2-dev.108.27487 178 3/15/2023
1.1.1 334 3/15/2023
1.1.1-dev.108.14980 178 3/15/2023
1.1.1-dev.108.13289 183 3/15/2023
1.1.1-dev.107.27144 177 3/14/2023
1.1.0 340 3/14/2023
1.1.0-workflow-dev.107.22552 185 3/14/2023
1.1.0-workflow-dev.107.21746 177 3/14/2023
1.1.0-workflow-dev.107.21506 178 3/14/2023
1.1.0-workflow-dev.107.20979 184 3/14/2023
1.1.0-dev.107.26364 180 3/14/2023
1.1.0-dev.107.24396 172 3/14/2023
1.1.0-dev.107.22787 186 3/14/2023
1.0.6 418 3/5/2022