private async Task ReplayComponentsJobConfigs(MessageBrokerChannelModel channelModel) { var componentJobs = await _componentRegistry.GetAllComponentJobConfigsAsync( channelModel.ComponentId); foreach (var componentJob in componentJobs) { var serializedComponentJob = JsonConvert.SerializeObject(componentJob); var message = new MessageBrokerMessage("key", serializedComponentJob); await _producer.ProduceAsync(channelModel.UpdateChannelName, message); } }
public Task CreateChannel(MessageBrokerChannelModel channelModel) { _logger.LogWarning("CreateChannel did nothing"); return(Task.CompletedTask); }
public async Task ProcessRequestAsync(RegistrationRequestMessage request) { if (string.IsNullOrWhiteSpace(request.ComponentId)) { throw new ArgumentException( "Argument must be valid component name" , nameof(request.ComponentId)); } if (string.IsNullOrWhiteSpace(request.ComponentType)) { throw new ArgumentException("Component type must not be empty" , nameof(request.ComponentType)); } else if (request.ComponentType != _componentIdentifiers.AnalyserComponentTypeName && request.ComponentType != _componentIdentifiers.DataAcquirerComponentTypeName) { throw new ArgumentOutOfRangeException( nameof(request.ComponentType), "Component type must be valid component identifier"); } if (string.IsNullOrWhiteSpace(request.UpdateChannelName)) { throw new ArgumentException("Argument must be valid channel name" , nameof(request.UpdateChannelName)); } if (string.IsNullOrWhiteSpace(request.InputChannelName)) { throw new ArgumentException("Argument must be valid channel name" , nameof(request.InputChannelName)); } var channelModel = MessageBrokerChannelModel.FromRequest(request); ValidateAttributes(request.ComponentType, request.Attributes); var componentRegisterModel = new ComponentModel( request.ComponentId, request.ComponentType, request.InputChannelName, request.UpdateChannelName, request.Attributes); try { var subscribeComponentModel = await _subscribedComponentManager .SubscribeComponentAsync(componentRegisterModel); } catch (InvalidOperationException) { throw; } catch (Exception e) { _logger.LogError("Unexpected error while processing request: {errorMessage}", e.Message); throw; } await _messageBrokerApi.CreateChannel(channelModel); while (true) { try { await ReplayComponentsJobConfigs(channelModel); break; } catch (HttpRequestException hre) when(hre.Message.Contains("Connection refused")) { _logger.LogError("Could not contact storage. Will try again"); await Task.Delay(TimeSpan.FromSeconds(30)); } catch (Exception e) { _logger.LogError("Could not perform replay - exception: {exception}", e); throw new InvalidOperationException("could not replay components job config", e); } } }