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 187 7/24/2023
6.0.15 423 7/19/2022
6.0.14 453 7/10/2022
6.0.13 409 6/15/2022
6.0.12 402 6/15/2022
6.0.11 429 6/15/2022
6.0.10 422 6/11/2022
6.0.9 429 6/8/2022
6.0.8 428 5/26/2022
6.0.8-beta.3 116 5/24/2022
6.0.8-beta.2 115 5/24/2022
6.0.7 433 5/18/2022
6.0.6 460 4/28/2022
6.0.5 452 3/30/2022
6.0.5-beta.20 123 4/27/2022
6.0.5-beta.19 119 4/25/2022
6.0.5-beta.18 122 4/22/2022
6.0.5-beta.17 129 4/16/2022
6.0.5-beta.16 133 4/8/2022
6.0.5-beta.15 124 4/8/2022
6.0.5-beta.14 134 4/7/2022
6.0.5-beta.13 132 4/7/2022
6.0.5-beta.12 134 4/6/2022
6.0.5-beta.11 125 4/6/2022
6.0.5-beta.10 123 3/31/2022
6.0.5-beta.9 137 3/26/2022
6.0.5-beta.8 137 3/22/2022
6.0.5-beta.7 127 3/21/2022
6.0.5-beta.6 137 3/14/2022
6.0.5-beta.5 129 3/2/2022
6.0.5-beta.4 129 2/22/2022
6.0.5-beta.3 131 2/18/2022
6.0.5-beta.2 125 2/18/2022
6.0.5-beta.1 132 2/16/2022
6.0.4 463 2/10/2022
6.0.3 459 2/9/2022
6.0.3-beta.9 129 2/10/2022
6.0.3-beta.7 139 1/27/2022
6.0.3-beta.6 137 1/19/2022
6.0.3-beta.5 139 1/17/2022
6.0.3-beta.4 138 1/16/2022
6.0.3-beta.3 136 1/14/2022
6.0.3-beta.2 140 1/13/2022
6.0.3-beta.1 158 1/11/2022
6.0.2 316 1/6/2022
6.0.1 901 12/3/2021
3.1.11 345 11/17/2021
3.1.10 438 7/29/2021
3.1.9 349 7/1/2021
3.1.8 416 12/15/2020
3.1.6 512 9/16/2020
3.1.5 448 9/8/2020
3.1.1 497 6/23/2020
3.1.0 534 5/24/2020
1.0.1 508 5/4/2020