NetPro.RabbitMQ 6.0.16

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

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

NetPro.RabbitMQ使用

使用

NuGet

初始化Rabbit服务(代码方式)
 services.AddRabbitMqClient(new RabbitMqClientOptions
 {
     HostName = "192.168.7.66",
     Port = 5672,
     Password = "guest",
     UserName = "guest",
     VirtualHost= "/",
 })
 .AddProductionExchange("LeonTest", new RabbitMqExchangeOptions
     {
         DeadLetterExchange = "DeadExchange", //不为空,默认不重发
         AutoDelete = false,
         Type = "fanout",
         Durable = true,
         Queues = new List<RabbitMqQueueOptions> { new RabbitMqQueueOptions { AutoDelete = false, Exclusive = false, Durable = true, Name = "myqueue", RoutingKeys = new HashSet<string> { "mini", "yang" } } }
     })
     .AddConsumptionExchange($"{LeonTest}", new RabbitMqExchangeOptions
            {
                DeadLetterExchange = "DeadExchange", //不为空,默认不重发
                AutoDelete = false,
                Type = ExchangeType.Direct,
                Durable = true,
                Queues = new List<RabbitMqQueueOptions> { new RabbitMqQueueOptions { AutoDelete = false, Exclusive = false, Durable = true, Name = $"{myqueue}", RoutingKeys = new HashSet<string> { "myqueue" } } }
            }).AddMessageHandlerSingleton<CustomMessageHandler>("myqueue");

            services.BuildServiceProvider().GetRequiredService<IQueueService>().StartConsuming();;
"RabbitMq": {
	"HostName": "127.0.0.1",
	"Port": "5672",
	"UserName": "guest",
	"Password": "guest"
    },
"RabbitMqExchange": {
	"Type": "direct",
	"Durable": true,
	"AutoDelete": false,
	"DeadLetterExchange": "default.dlx.exchange",
	"RequeueFailedMessages": true,
	"Queues": [
		{
		 "Name": "myqueue",
		 "RoutingKeys": [ "routing.key" ]
		}]
	}

生产消息


namespace MQ.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly IQueueService _queueService;
        public ValuesController(IQueueService queueService)
        {
            _queueService = queueService;
        }
        // GET api/values
        [HttpGet]
        [Route("Send")]
        public ActionResult<IEnumerable<string>> Send(string mes)
        {
            _queueService.Send(//发送消息
                                @object: $"{mes}",
                                exchangeName: "LeonTest",
                                routingKey: "yang"
                                 );
            return new string[] { "value1", "value2" };
        }
    }
}
 }

消费消息

namespace ReceiveB.Service
{
    //继承IMessageHandler,即可作为消费者消费消息
    public class CustomMessageHandler : IMessageHandler
    {
         private readonly IServiceScopeFactory _serviceScopeFactory;
        readonly ILogger<CustomMessageHandler> _logger;
        public CustomMessageHandler(ILogger<CustomMessageHandler> logger,
          IServiceScopeFactory serviceScopeFactory)
        {
            //由于消费者在BuildServiceProvider()之前就执行导致对象还没注入,所以此处不支持自定义类型的实例注入,只能通过IServiceScopeFactory来获取servcie实例
            _logger = logger;
            _serviceScopeFactory = serviceScopeFactory;
        }

        public void Handle(string message, string routingKey)
        {
            using var scope = _serviceScopeFactory.CreateScope();
            var _redisOptionService = scope.ServiceProvider.GetRequiredService<IRedisOptionService>();

            Console.WriteLine($"正在消费消息");
            _logger.LogInformation("");
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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
6.0.16 149 7/24/2023
6.0.15 406 7/19/2022
6.0.14 428 7/10/2022
6.0.13 383 6/15/2022
6.0.12 386 6/15/2022
6.0.11 403 6/15/2022
6.0.10 396 6/11/2022
6.0.9 395 6/8/2022
6.0.8 402 5/26/2022
6.0.8-beta.3 102 5/24/2022
6.0.8-beta.2 102 5/24/2022
6.0.7 417 5/18/2022
6.0.6 433 4/28/2022
6.0.5 417 3/30/2022
6.0.5-beta.20 110 4/27/2022
6.0.5-beta.19 106 4/25/2022
6.0.5-beta.18 107 4/22/2022
6.0.5-beta.17 115 4/16/2022
6.0.5-beta.16 119 4/8/2022
6.0.5-beta.15 111 4/8/2022
6.0.5-beta.14 121 4/7/2022
6.0.5-beta.13 118 4/7/2022
6.0.5-beta.12 121 4/6/2022
6.0.5-beta.11 112 4/6/2022
6.0.5-beta.10 109 3/31/2022
6.0.5-beta.9 124 3/26/2022
6.0.5-beta.8 123 3/22/2022
6.0.5-beta.7 114 3/21/2022
6.0.5-beta.6 123 3/14/2022
6.0.5-beta.5 113 3/2/2022
6.0.5-beta.4 116 2/22/2022
6.0.5-beta.3 118 2/18/2022
6.0.5-beta.2 113 2/18/2022
6.0.5-beta.1 119 2/16/2022
6.0.4 438 2/10/2022
6.0.3 427 2/9/2022
6.0.3-beta.9 117 2/10/2022
6.0.3-beta.7 127 1/27/2022
6.0.3-beta.6 125 1/19/2022
6.0.3-beta.5 127 1/17/2022
6.0.3-beta.4 127 1/16/2022
6.0.3-beta.3 125 1/14/2022
6.0.3-beta.2 128 1/13/2022
6.0.3-beta.1 146 1/11/2022
6.0.2 287 1/6/2022
6.0.1 885 12/3/2021
3.1.11 330 11/17/2021
3.1.10 406 7/29/2021
3.1.9 325 7/1/2021
3.1.8 390 12/15/2020
3.1.6 483 9/16/2020
3.1.5 422 9/8/2020
3.1.1 467 6/23/2020
3.1.0 504 5/24/2020
1.0.1 493 5/4/2020