Beispiel #1
0
        public MqttIpcClient(MqttIpcClientConfiguration conf, IIpcPacketRouter router, IIpcSerializer serializer)
        {
            _router        = router;
            _serializer    = serializer;
            _packetFactory = new PacketContainerFactory();
            _client        = new MqttFactory().CreateManagedMqttClient(new MqttNetLogger(conf.ClientName));
            _options       = new ManagedMqttClientOptionsBuilder()
                             .WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
                             .WithClientOptions(new MqttClientOptionsBuilder()
                                                .WithClientId(conf.ClientName)
                                                .WithTcpServer(conf.EndPoint)
                                                .Build())
                             .Build();

            _client.ConnectedHandler    = new MqttClientConnectedHandlerDelegate(Client_OnConnected);
            _client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(Client_OnDisconnected);
        }
Beispiel #2
0
        private MqttIpcClient(MqttIpcClientConfiguration conf, IIpcPacketRouter router, IIpcSerializer serializer)
        {
            _router          = router;
            _serializer      = serializer;
            _endPoint        = conf.EndPoint;
            _name            = conf.ClientName;
            _responsesQueues = new HashSet <string>();
            _pendingRequests = new ConcurrentDictionary <Guid, PendingRequest>();
            _packetFactory   = new PacketContainerFactory();
            _requestFactory  = new PendingRequestFactory();
            _client          = new MqttFactory().CreateManagedMqttClient(new MqttNetLogger(conf.ClientName));
            ManagedMqttClientOptions options = new ManagedMqttClientOptionsBuilder()
                                               .WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
                                               .WithClientOptions(new MqttClientOptionsBuilder()
                                                                  .WithClientId(_name)
                                                                  .WithTcpServer(_endPoint)
                                                                  .Build())
                                               .Build();

            _client.ApplicationMessageReceived += (sender, args) => OnMessage(args.ClientId, args.ApplicationMessage);
            _client.StartAsync(options).ConfigureAwait(false).GetAwaiter().GetResult();
        }