An implemention of SwitchSoftware.Messaging.Queues for RabbitMQ
License
—
Deps
3
Install Size
—
Vulns
✓ 0
Published
Jul 15, 2024
$ dotnet add package SwitchSoftware.Messaging.Queues.RabbitMQRabbitMQ implementation of SwitchSoftware.Messaging.Queues
MessagePublisher
MessageQueueListener
nuget repo : https://www.nuget.org/packages/SwitchSoftware.Messaging.Queues.RabbitMQ
There are also versions for .net core 6.0 and 5.0
Create a class that inherits RabbitMQMessageQueueListener to listen on "myQueue" and handle requests in the handlerequest method:
{
private readonly ILogger<MyQueueListener> _logger;
private const string RouteKey = "myRouteKey";
private const string QueueName = "myQueueName";
public MyQueueListener(IConfiguration configuration, ILogger<MyQueueListener> logger)
: base(configuration, logger, RouteKey, QueueName)
{
_logger = logger;
}
public override async Task<bool> ProcessAsync(string message)
{
Console.WriteLine($"received: {message}");
}
}
Start listening:
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _myQueueListener.StartListening(stoppingToken);
}
You will need to pass an IConfiguration and ILogger instances as well.
The listener relies on the following app settings (adjust to your RabbitMQ instance):
"HostName": "localhost",
"Username": "guest",
"Password": "guest",
"VirtualHost": "/"
}
Versions
8.0.0 Version for .net Core 8
6.0.4 Minor fix in configuration parsing of enableSSL setting
6.0.3 Added new optional enable SSL setting in configuration. False if omitted. Usage: EnableSsl: true;
6.0.2 Added new optional Port setting in configuration to support using a specific rabbit mq port. If not provided, default port is used.
6.0.1 using net core 6.0
2.0.1 Added configurable settings for consumer prefetch count and consumer prefetch shared based on the RabbitMQ Consumer Prefetch Specifications two new settings are added to the RabbitMQ configuration section:
ConsumerPrefetchCount: an integer value representing the maximum number of unacknowledged messages at once. Default value (if not specified) is 0, which sets no limit on the number of unacknowledged messages.
ConsumerPrefetchShared: a boolean value representing whether the consumer prefetch count is applied applied separately to each new consumer on the channel or shared across all consumers on the channel. Default value (if not specified) is false.
Also check this post for more details.
2.0.0