-
-
Save gdyrrahitis/48b83bb14b6ef3220d4afc9706dc5706 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 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