internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings, Func <IPAddress, int, Task <IChannel> > channelFactory) : base(settings) { this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue <Message>(); this.completionQueue = new Queue <string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; this.qos = settings.PublishToServerQoS; this.eventLoopGroupKey = iotHubConnectionString.IotHubName + "#" + iotHubConnectionString.DeviceId + "#" + iotHubConnectionString.Audience; if (channelFactory == null) { switch (settings.GetTransportType()) { case TransportType.Mqtt_Tcp_Only: this.channelFactory = this.CreateChannelFactory(iotHubConnectionString, settings); break; case TransportType.Mqtt_WebSocket_Only: this.channelFactory = this.CreateWebSocketChannelFactory(iotHubConnectionString, settings); break; default: throw new InvalidOperationException("Unsupported Transport Setting {0}".FormatInvariant(settings.GetTransportType())); } } else { this.channelFactory = channelFactory; } this.closeRetryPolicy = new RetryPolicy(new TransientErrorIgnoreStrategy(), 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }
internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings, Func <IPAddress, int, Task <IChannel> > channelFactory) : base(settings) { this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue <Message>(); this.completionQueue = new Queue <string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; this.qos = settings.PublishToServerQoS; this.eventLoopGroupKey = iotHubConnectionString.IotHubName + "#" + iotHubConnectionString.DeviceId + "#" + iotHubConnectionString.Audience; this.channelFactory = channelFactory ?? this.CreateChannelFactory(iotHubConnectionString, settings); this.closeRetryPolicy = new RetryPolicy(new TransientErrorIgnoreStrategy(), 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }
internal MqttTransportHandler( IPipelineContext context, IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings, Func <IPAddress[], int, Task <IChannel> > channelFactory, Action <object, ConnectionEventArgs> onConnectionOpenedCallback, Func <object, ConnectionEventArgs, Task> onConnectionClosedCallback) : base(context, settings) { this.connectionOpenedListener = onConnectionOpenedCallback; this.connectionClosedListener = onConnectionClosedCallback; this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue <Message>(); this.completionQueue = new Queue <string>(); this.serverAddresses = null; // this will be resolved asynchronously in OpenAsync this.hostName = iotHubConnectionString.HostName; this.receiveEventMessageFilter = string.Format(CultureInfo.InvariantCulture, receiveEventMessagePatternFilter, iotHubConnectionString.DeviceId, iotHubConnectionString.ModuleId); this.receiveEventMessagePrefix = string.Format(CultureInfo.InvariantCulture, receiveEventMessagePrefixPattern, iotHubConnectionString.DeviceId, iotHubConnectionString.ModuleId); this.qos = settings.PublishToServerQoS; this.eventLoopGroupKey = iotHubConnectionString.IotHubName + "#" + iotHubConnectionString.DeviceId + "#" + iotHubConnectionString.Audience; if (channelFactory == null) { switch (settings.GetTransportType()) { case TransportType.Mqtt_Tcp_Only: this.channelFactory = this.CreateChannelFactory(iotHubConnectionString, settings, context.Get <ProductInfo>()); break; case TransportType.Mqtt_WebSocket_Only: this.channelFactory = this.CreateWebSocketChannelFactory(iotHubConnectionString, settings, context.Get <ProductInfo>()); break; default: throw new InvalidOperationException("Unsupported Transport Setting {0}".FormatInvariant(settings.GetTransportType())); } } else { this.channelFactory = channelFactory; } this.closeRetryPolicy = new RetryPolicy(new TransientErrorIgnoreStrategy(), 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }
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(); }); }
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(); }); }
internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings, Func<IPAddress, int, Task<IChannel>> channelFactory) : base(settings) { this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue<Message>(); this.completionQueue = new Queue<string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; this.qos = settings.PublishToServerQoS; this.eventLoopGroupKey = iotHubConnectionString.IotHubName + "#" + iotHubConnectionString.DeviceId + "#" + iotHubConnectionString.Audience; this.channelFactory = channelFactory ?? this.CreateChannelFactory(iotHubConnectionString, settings); this.closeRetryPolicy = new RetryPolicy(new TransientErrorIgnoreStrategy(), 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }
internal MqttTransportHandler(IotHubConnectionString iotHubConnectionString, MqttTransportSettings settings, Func<IPAddress, int, Task<IChannel>> channelFactory) : base(settings) { this.mqttIotHubAdapterFactory = new MqttIotHubAdapterFactory(settings); this.messageQueue = new ConcurrentQueue<Message>(); this.completionQueue = new Queue<string>(); this.serverAddress = Dns.GetHostEntry(iotHubConnectionString.HostName).AddressList[0]; this.qos = settings.PublishToServerQoS; this.eventLoopGroupKey = iotHubConnectionString.IotHubName + "#" + iotHubConnectionString.DeviceId + "#" + iotHubConnectionString.Audience; if (channelFactory == null) { switch (settings.GetTransportType()) { case TransportType.Mqtt_Tcp_Only: this.channelFactory = this.CreateChannelFactory(iotHubConnectionString, settings); break; case TransportType.Mqtt_WebSocket_Only: this.channelFactory = this.CreateWebSocketChannelFactory(iotHubConnectionString, settings); break; default: throw new InvalidOperationException("Unsupported Transport Setting {0}".FormatInvariant(settings.GetTransportType())); } } else { this.channelFactory = channelFactory; } this.closeRetryPolicy = new RetryPolicy(new TransientErrorIgnoreStrategy(), 5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); }