NetPro.RabbitMQ
6.0.6
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetPro.RabbitMQ --version 6.0.6
NuGet\Install-Package NetPro.RabbitMQ -Version 6.0.6
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.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.RabbitMQ --version 6.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.RabbitMQ, 6.0.6"
#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.6 // Install NetPro.RabbitMQ as a Cake Tool #tool nuget:?package=NetPro.RabbitMQ&version=6.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NetPro.RabbitMQ使用
使用
初始化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 | Versions 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.
-
.NETCoreApp 3.1
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Console (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- RabbitMQ.Client (>= 5.1.2)
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Console (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- RabbitMQ.Client (>= 5.1.2)
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 | 182 | 7/24/2023 |
6.0.15 | 416 | 7/19/2022 |
6.0.14 | 448 | 7/10/2022 |
6.0.13 | 404 | 6/15/2022 |
6.0.12 | 397 | 6/15/2022 |
6.0.11 | 424 | 6/15/2022 |
6.0.10 | 417 | 6/11/2022 |
6.0.9 | 424 | 6/8/2022 |
6.0.8 | 421 | 5/26/2022 |
6.0.8-beta.3 | 113 | 5/24/2022 |
6.0.8-beta.2 | 112 | 5/24/2022 |
6.0.7 | 426 | 5/18/2022 |
6.0.6 | 455 | 4/28/2022 |
6.0.5 | 447 | 3/30/2022 |
6.0.5-beta.20 | 120 | 4/27/2022 |
6.0.5-beta.19 | 116 | 4/25/2022 |
6.0.5-beta.18 | 119 | 4/22/2022 |
6.0.5-beta.17 | 124 | 4/16/2022 |
6.0.5-beta.16 | 130 | 4/8/2022 |
6.0.5-beta.15 | 121 | 4/8/2022 |
6.0.5-beta.14 | 131 | 4/7/2022 |
6.0.5-beta.13 | 129 | 4/7/2022 |
6.0.5-beta.12 | 131 | 4/6/2022 |
6.0.5-beta.11 | 122 | 4/6/2022 |
6.0.5-beta.10 | 120 | 3/31/2022 |
6.0.5-beta.9 | 134 | 3/26/2022 |
6.0.5-beta.8 | 134 | 3/22/2022 |
6.0.5-beta.7 | 124 | 3/21/2022 |
6.0.5-beta.6 | 134 | 3/14/2022 |
6.0.5-beta.5 | 126 | 3/2/2022 |
6.0.5-beta.4 | 126 | 2/22/2022 |
6.0.5-beta.3 | 128 | 2/18/2022 |
6.0.5-beta.2 | 122 | 2/18/2022 |
6.0.5-beta.1 | 129 | 2/16/2022 |
6.0.4 | 458 | 2/10/2022 |
6.0.3 | 454 | 2/9/2022 |
6.0.3-beta.9 | 126 | 2/10/2022 |
6.0.3-beta.7 | 136 | 1/27/2022 |
6.0.3-beta.6 | 132 | 1/19/2022 |
6.0.3-beta.5 | 136 | 1/17/2022 |
6.0.3-beta.4 | 135 | 1/16/2022 |
6.0.3-beta.3 | 133 | 1/14/2022 |
6.0.3-beta.2 | 135 | 1/13/2022 |
6.0.3-beta.1 | 153 | 1/11/2022 |
6.0.2 | 309 | 1/6/2022 |
6.0.1 | 896 | 12/3/2021 |
3.1.11 | 338 | 11/17/2021 |
3.1.10 | 431 | 7/29/2021 |
3.1.9 | 344 | 7/1/2021 |
3.1.8 | 411 | 12/15/2020 |
3.1.6 | 507 | 9/16/2020 |
3.1.5 | 443 | 9/8/2020 |
3.1.1 | 492 | 6/23/2020 |
3.1.0 | 529 | 5/24/2020 |
1.0.1 | 503 | 5/4/2020 |