Esempio n. 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _sensorStateUpdater.Start(stoppingToken);
            var sensorStates = _sensorStateUpdater.CreateObservableDataStream();
            var messages     = await _mqttClient.CreateMessageStreamAsync(stoppingToken);

            var messagesWithState         = MessageProcessor.CombineMqMessagesWithSensorState(messages, sensorStates);
            var messageProcessingPipeline =
                _messageProcessor.CreateMessageProcessingPipeline(stoppingToken, messagesWithState);

            _subscription = messageProcessingPipeline
                            .Do(message => { }, exception => { _log.Error(exception, "Message processing pipeline failed."); })
                            .Retry()
                            .Subscribe(action =>
            {
                try
                {
                    action.Process(_actionProcessor);
                }
                catch (Exception e)
                {
                    _log.Error(e, "Processing action {@action} failed.", action);
                }
            }, exception => { _log.Fatal(exception, "Message processing pipeline failed."); });
        }