protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("Clearing file {path}", settings.OutFilePath); System.IO.File.WriteAllText(settings.OutFilePath, ""); await ProgramCommon.WaitForRabbitMQ(stoppingToken); await client.TryConnect( Constants.RabbitUri, Constants.ExchangeName, Constants.AllMyTopics, stoppingToken); logger.LogInformation("Connected"); await Task.Delay(Constants.DelayAfterConnect, stoppingToken); // keep the service running while (!stoppingToken.IsCancellationRequested) { await Task.Delay(Constants.LoopDelay, stoppingToken); } logger.LogInformation("Finished"); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await ProgramCommon.WaitForRabbitMQ(stoppingToken); await original.TryConnect(Constants.RabbitUri, Constants.ExchangeName, Constants.OriginalTopic, stoppingToken); await intermediate.TryConnect(Constants.RabbitUri, Constants.ExchangeName, Constants.IntermediateTopic, stoppingToken); logger.LogInformation("Connected"); await Task.Delay(Constants.DelayAfterConnect, stoppingToken); // keep the service running while (!stoppingToken.IsCancellationRequested) { await Task.Delay(Constants.LoopDelay, stoppingToken); } logger.LogInformation("Finished"); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var stopWatch = System.Diagnostics.Stopwatch.StartNew(); await ProgramCommon.WaitForRabbitMQ(stoppingToken); await rabbitClient.TryConnect(Constants.RabbitUri, Constants.ExchangeName, Constants.OriginalTopic, stoppingToken); logger.LogInformation("Connected"); await Task.Delay(Constants.DelayAfterConnect, stoppingToken); int messageToSend = 1; while (!stoppingToken.IsCancellationRequested && messageToSend <= Constants.MaximumNumberOfMessagesToSend) { rabbitClient.SendMessage($"MSG_{messageToSend}"); ++messageToSend; await Task.Delay(Constants.DelayBetweenMessages, stoppingToken); } logger.LogInformation("Finished sending messages after {TotalSeconds} seconds", stopWatch.Elapsed.TotalSeconds); }