Z.RabbitMQ 1.0.0

dotnet add package Z.RabbitMQ --version 1.0.0                
NuGet\Install-Package Z.RabbitMQ -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="Z.RabbitMQ" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Z.RabbitMQ --version 1.0.0                
#r "nuget: Z.RabbitMQ, 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 Z.RabbitMQ as a Cake Addin
#addin nuget:?package=Z.RabbitMQ&version=1.0.0

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

Z.RabbitMQ

基于.NET 平台 C# 语言 提供的RabbitM负载均衡

RabbitMQ使用

使用

  • 添加通信管道

     // 注入事件总线
    services.ServiceRabbitMQ();
    
  • 存在参数Action<ConnectionFactory>配置默认的链接Factory

    services.ServiceRabbitMQ(c =>
    {
        c.DispatchConsumersAsync = false; //关闭异步
    });
    
IRabbitEventManager定义
  • 构造函数注入IRabbitEventManager
 private readonly IRabbitEventManager _rabbitEventManager;
消费者抽象类
  • 继承RabbitConsumer<T>
    • 实现void Exec接口
  • 继承RabbitConsumerAsync<T>
    • 实现Task Exec接口
测试方法
  • CommentsConsumer是继承抽象类消费者

  • Comments是传输数据的Data

  • "comment"队列名称

  • 推送rabbit队列

    •   /// <summary>
        /// 推送rabbit队列
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task RabbitPublish()
        {
            await _rabbitEventManager.PublishAsync<CommentsConsumer, Comments>(
                 "comment",
                 new Comments()
                 {
                     //"moduleId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                     // "rootId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                     // "parentId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                     // "replyAccountId": "string",
                     // "content": "fdsafd发顺丰"
                     ModuleId = Guid.NewGuid(),
                     RootId = Guid.NewGuid(),
                     ParentId = Guid.NewGuid(),
                     ReplyAccountId = Guid.NewGuid().ToString("N"),
                     Content = $"测试消息队列 Guid:{Guid.NewGuid()}"
                 }
             );
        }
      
  • 订阅rabbit队列

    •   /// <summary>
        /// 订阅rabbit队列
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task RabbitSubscribe()
        {
            await _rabbitEventManager.SubscribeAsync<CommentsConsumer>("comment");
        }
      
    • public async Task SubscribeAsync<T>(
          string queueName,//队列名称
          string configName = "",//链接配置名称
          int queueCount = 1,//队列个数
          int xMaxPriority = 0,//优先级
          bool isDLX = false,//是否死信
          CancellationToken cancellationToken = default
      )
      
  • 消费死信队列

    • /// <summary>
      /// 消费死信队列
      /// </summary>
      /// <returns></returns>
      [HttpGet]
      public async Task RabbitSubscribeDLXAsync()
      {
          await _rabbitEventManager.SubscribeDLXAsync<CommentsConsumer>("comment");
      }
      
  • 取消订阅

    • /// <summary>
      /// 取消订阅
      /// </summary>
      /// <returns></returns>
      [HttpGet]
      public async Task RabbitUnSubscribe()
      {
           await _rabbitEventManager.UnSubscribeAsync<CommentsConsumer>("comment");
      }
      
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Z.RabbitMQ:

Package Downloads
Z.Fantasy.Core

Core包

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 211 12/27/2023