public async Task SubscribeToSettingsSender(Func <FileFormatterSettings> settingsCollector, IServiceBusConfiguration configuration) { _ctsSender = new CancellationTokenSource(); var queueController = new AzureMessagesTopicController(configuration); if (!queueController.QueueExist().GetAwaiter().GetResult()) { throw new InvalidOperationException($"Wrong configuration '{configuration.ConfigurationName}' or queue doesn't exist."); } await Task.Run(async() => { while (!_ctsSender.Token.IsCancellationRequested) { var settings = settingsCollector(); if (settings != null) { var settingsMessages = new[] { new SettingsMessageItem { NewPageTimeout = settings.NewPageTimeOut, ServiceStatus = settings.ServiceStatus.HasValue ? Enum.GetName(settings.ServiceStatus.GetType(), settings.ServiceStatus) : null, NodeName = settings.NodeName, Date = settings.Date } }; try { await queueController.SendMessagesAsync(settingsMessages); } catch { //to log } } Thread.Sleep(SendSettingsPeriod); } }, _ctsSender.Token); }
private bool TryCreateQueues() { try { var statusQueueController = new AzureMessagesTopicController(_statusQueueConfig); var controlQueueController = new AzureMessagesTopicController(_controlQueueConfig); Task.WaitAll(_fileQueueController.CreateQueueAsync(), statusQueueController.CreateQueueAsync(), controlQueueController.CreateQueueAsync()); return(true); } catch { //to log return(false); } }