Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis

gdyrrahitis/LogConsumer.cs Secret

Created May 16, 2020
Embed
What would you like to do?
public class LogConsumer : ConsumerBase, IHostedService
{
protected override string QueueName => "CUSTOM_HOST.log.message";
public LogConsumer(
IMediator mediator,
ConnectionFactory connectionFactory,
ILogger<LogConsumer> logConsumerLogger,
ILogger<ConsumerBase> consumerLogger,
ILogger<RabbitMqClientBase> logger) :
base(mediator, connectionFactory, consumerLogger, logger)
{
try
{
var consumer = new AsyncEventingBasicConsumer(Channel);
consumer.Received += OnEventReceived<LogCommand>;
Channel.BasicConsume(queue: QueueName, autoAck: false, consumer: consumer);
}
catch (Exception ex)
{
logConsumerLogger.LogCritical(ex, "Error while consuming message");
}
}
public virtual Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public virtual Task StopAsync(CancellationToken cancellationToken)
{
Dispose();
return Task.CompletedTask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.