public async Task <int> RunAsync() { var token = _applicationLifetime.ApplicationStopping; _logger.LogInformation("Main executed"); // send to a queue //await _producerService.SendToQueueAsync(token); //await _consumerService.StartReceivingQueueAsync(token); //await Task.Delay(TimeSpan.FromSeconds(5), token); //await _consumerService.StopReceivingQueueAsync(token); // send to a topic await _producerService.SendToTopic(token); await _consumerService.StartReceivingTopicAsync(token); await Task.Delay(TimeSpan.FromSeconds(5), token); await _consumerService.StopReceivingTopicAsync(token); // use this token for stopping the services token.ThrowIfCancellationRequested(); return(0); }