Skip to content

Instantly share code, notes, and snippets.


gdyrrahitis/LogConsumer.cs Secret

Created May 16, 2020
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)
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)
return Task.CompletedTask;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment