Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class LogBackgroundTask : BackgroundService
private readonly IRabbitMqProducer<LogIntegrationEvent> _producer;
public LogBackgroundTask(IRabbitMqProducer<LogIntegrationEvent> producer) => _producer = producer;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
while (!stoppingToken.IsCancellationRequested)
var @event = new LogIntegrationEvent
Id = Guid.NewGuid(),
Message = $"Hello! Message generated at {DateTime.Now.ToString("O")}"
await Task.Delay(20000, stoppingToken);
await Task.CompletedTask;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment