internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings)
        {
            this.DefaultReceiveTimeout = DefaultReceiveTimeoutInSeconds;
            this.connectCompletion = new TaskCompletionSource();
            this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings);
            this.messageQueue = new ConcurrentQueue<Message>();
            this.completionQueue = new Queue<string>();
            this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0];
            var group = new SingleInstanceEventLoopGroup();
            this.qos = settings.PublishToServerQoS;

            this.bootstrap = new Bootstrap()
                .Group(@group)
                .Channel<TcpSocketChannel>()
                .Option(ChannelOption.TcpNodelay, true)
                .Handler(new ActionChannelInitializer<ISocketChannel>(ch =>
                {
                    ch.Pipeline.AddLast(
                        TlsHandler.Client(iotHubConnectionString.HostName, null),
                        MqttEncoder.Instance,
                        new MqttDecoder(false, 256 * 1024),
                        this.mqttIotHubAdapterFactory.Create(
                            this.OnConnected,
                            this.OnMessageReceived,
                            this.OnError, 
                            iotHubConnectionString, 
                            settings));
                }));

            this.ScheduleCleanup(async () =>
            {
                this.connectCompletion.TrySetCanceled();
                await group.ShutdownGracefullyAsync();
            });

        }
Ejemplo n.º 2
0
        internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings)
        {
            this.DefaultReceiveTimeout    = DefaultReceiveTimeoutInSeconds;
            this.connectCompletion        = new TaskCompletionSource();
            this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings);
            this.messageQueue             = new ConcurrentQueue <Message>();
            this.completionQueue          = new Queue <string>();
            this.serverAddress            = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0];
            var group = new SingleInstanceEventLoopGroup();

            this.qos = settings.PublishToServerQoS;

            this.bootstrap = new Bootstrap()
                             .Group(@group)
                             .Channel <TcpSocketChannel>()
                             .Option(ChannelOption.TcpNodelay, true)
                             .Handler(new ActionChannelInitializer <ISocketChannel>(ch =>
            {
                ch.Pipeline.AddLast(
                    TlsHandler.Client(iotHubConnectionString.HostName, null),
                    MqttEncoder.Instance,
                    new MqttDecoder(false, 256 * 1024),
                    this.mqttIotHubAdapterFactory.Create(
                        this.OnConnected,
                        this.OnMessageReceived,
                        this.OnError,
                        iotHubConnectionString,
                        settings));
            }));

            this.ScheduleCleanup(async() =>
            {
                this.connectCompletion.TrySetCanceled();
                await group.ShutdownGracefullyAsync();
            });
        }