示例#1
0
 public MqttService(MqttClient mqttClient, MqttServiceSettings settings, IMessageBus messageBus, IObjectSerializer serializer, ILogger logger)
 {
     _mqttClient   = mqttClient ?? throw new ArgumentNullException(nameof(mqttClient));
     _settings     = settings ?? throw new ArgumentNullException(nameof(settings));
     _messageBus   = messageBus ?? throw new ArgumentNullException(nameof(messageBus));
     _serializer   = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _topicMatcher = new TopicMatcher(settings);
     _mqttClient.ConnectionClosed       += ConnectionClosed;
     _mqttClient.MqttMsgPublishReceived += MessageReceived;
 }
示例#2
0
        public MqttServiceFactory(IOptions <MqttServiceSettings> options, ILogger <MqttServiceFactory> logger, IMessageBus messageBus, IObjectSerializer serializer)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.EnsureValueNotNull();

            _settings   = options.Value;
            _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
            _messageBus = messageBus ?? throw new ArgumentNullException(nameof(messageBus));
            _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
        }
示例#3
0
 public TopicMatcher(MqttServiceSettings settings)
 {
     _stateRegex      = ParseTopicToRegex(settings.StateTopic);
     _measurmentRegex = ParseTopicToRegex(settings.MeasurmentTopic);
     _registerRegex   = ParseTopicToRegex(settings.RegisterTopic);
 }