This repository was archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Allowing us to add our own Hosting Service #101
Copy link
Copy link
Open
Description
I have been using this library for a while, and let me say that it was a great help and time saver.
I use the hosting service to set the baseQos for the channel, with the hosted service added automatically with the AddMqServices extension method, i can only set the value for after the first batch, which could be deadly if i have a huge number of messages waiting in the queue, or when creating a new pod to help with the messages
this is an example for my hosting service, and i had to make a new custom extension for adding the mq service as a workaround
public class MQConsumingService : IHostedService
{
readonly IConsumingService _consumingService;
private readonly IConfiguration _configuration;
readonly ILogger<MQConsumingService> _logger;
public MQConsumingService(
IConsumingService consumingService,
IConfiguration configuration,
ILogger<MQConsumingService> logger)
{
_consumingService = consumingService;
_configuration = configuration;
_logger = logger;
}
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Starting consuming.");
var rabbitMqClientOptions = _configuration.GetSection("RabbitMq").Get<MqServiceOptions>();
_consumingService.Channel.BasicQos(rabbitMqClientOptions.PrefetchSize, rabbitMqClientOptions.PrefetchCount, rabbitMqClientOptions.Global);
_consumingService.StartConsuming();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping consuming.");
_consumingService.StopConsuming();
return Task.CompletedTask;
}
}Metadata
Metadata
Assignees
Labels
No labels