ArielCore.RabbitMqLib 1.0.2

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

使用步骤:

如果仅使用发布者,则只需要提供appsettings.json里的配置,和 services.AddMyRabbitMQ(builder.Configuration); 方法即可。

如果需要使用事件队列消费者,则需要添加两个方法调用,一是把EventHandler添加到容器中,二是需要在app创建后调用UseMyEventHandler(); 代码执行如上文所说,会从Ioc容器里找到所有的实现,并调用他们的Begin方法开启监听。

  1. 在Program.cs中加上如下代码(注意需要引用项目ArielCore.RabbitMqLib)
  #region 添加RabbitMQ到services
  builder.Services.AddArielRabbitMQ(builder.Configuration);

  // 当前程序集所有类型
  var currentAssemblyTypes = Assembly.GetExecutingAssembly().GetTypes();
  builder.Services.AddArielRabbitMQEventHandlers(currentAssemblyTypes); 

  // 上面参数可以像下面这样配置
  // builder.Services.AddMyRabbitMQEventHandlers(new Type[]{typeof(MyHandler1), typeof(MyHandler2), typeof(MyHandler3)}); 
  // builder.Services.AddMyRabbitMQEventHandlers(typeof(MyHandler1), typeof(MyHandler2), typeof(MyHandler3)); 

  #endregion

启动 如:

#region 使用 MyEventHandler
app.UseArielEventHandler();
#endregion
  1. 在appsettings.json文件中添加如下
"ArielRabbitMQOptions": {
  "UserName": "admin",
  "Password": "Aa123456.",
  "Host": "192.168.124.220",
  "VirtualHost": "EDCVHOST",
  "Port": 4996,
  "ExchangeName": "PerryExchange"
}
  1. 在Controller中。如
  public class PublishArielDataController : ApiControllerBase
  {
      #region params

      public IArielPublisher<PerryTest> _capPublisher { get; }

      #endregion

      #region 构造函数
      /// <summary>
      /// 构造函数
      /// </summary>
      public PublishArielDataController(IArielPublisher<PerryTest> capPublisher)
      {
          _capPublisher = capPublisher;
      }
      #endregion

      //发送消息
      [HttpGet("send")]
      public async Task<ActionResult> SendMessage()
      {
          var data = new PerryTest()
          {
              Id = Guid.NewGuid(),
              Name = "AAA",
              Count = 123,
              Remark = "哈哈哈"
          };

          await _capPublisher.PublishAsync(data);
          return Ok();
      }
  }
  1. 添加如如下类
  [QueueName("perry.test")]
  public class PerryTest
  {
      public Guid Id { get; set; }
      public string? Name { get; set; }
      public int Count { get; set; }
      public string? Remark { get; set; }
  }

  public class PerryTestEventHandler : ArielEventHandler<PerryTest>
  {
      public override Task OnReceivedAsync(PerryTest data, string message)
      {
          Console.WriteLine(message);
          return Task.CompletedTask;
      }

      public override void OnConsumerException(Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }
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.  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. 
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.0.2 187 12/23/2025
1.0.1 237 3/31/2025
1.0.0 171 5/9/2024