-
-
Save gdyrrahitis/ecfb4c4ffb99a8d339ff36760a2c9afe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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