Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created May 16, 2020 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/48b83bb14b6ef3220d4afc9706dc5706 to your computer and use it in GitHub Desktop.
Save gdyrrahitis/48b83bb14b6ef3220d4afc9706dc5706 to your computer and use it in GitHub Desktop.
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")}"
};
_producer.Publish(@event);
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