IotHubClient(DeviceClient deviceClient, string deviceId, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { this.deviceClient = deviceClient; this.deviceId = deviceId; this.settings = settings; this.allocator = allocator; this.messageAddressConverter = messageAddressConverter; }
IotHubClient(DeviceClient deviceClient, string deviceId, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { this.deviceClient = deviceClient; this.deviceId = deviceId; this.settings = settings; this.allocator = allocator; this.messageAddressConverter = messageAddressConverter; deviceClient.OperationTimeoutInMilliseconds = 0;// uint.MaxValue;// 6 * 60 * 1000; }
public static Func<IDeviceIdentity, Task<IMessagingServiceClient>> PreparePoolFactory(string baseConnectionString, int connectionPoolSize, TimeSpan? connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { IotHubConnectionStringBuilder csb = IotHubConnectionStringBuilder.Create(baseConnectionString); Func<IDeviceIdentity, Task<IMessagingServiceClient>> mqttCommunicatorFactory = deviceIdentity => { var identity = (IotHubDeviceIdentity)deviceIdentity; csb.AuthenticationMethod = DeriveAuthenticationMethod(csb.AuthenticationMethod, identity); csb.HostName = identity.IotHubHostName; string connectionString = csb.ToString(); return CreateFromConnectionStringAsync(identity.Id, connectionString, connectionPoolSize, connectionIdleTimeout, settings, allocator, messageAddressConverter); }; return mqttCommunicatorFactory; }
Bootstrapper(ISettingsProvider settingsProvider, ISessionStatePersistenceProvider sessionStateManager, IQos2StatePersistenceProvider qos2StateProvider, IMessageAddressConverter addressConverter) { Contract.Requires(settingsProvider != null); Contract.Requires(sessionStateManager != null); this.closeCompletionSource = new TaskCompletionSource(); this.settingsProvider = settingsProvider; this.settings = new Settings(this.settingsProvider); this.iotHubClientSettings = new IotHubClientSettings(this.settingsProvider); this.sessionStateManager = sessionStateManager; this.qos2StateProvider = qos2StateProvider; this.authProvider = new SasTokenDeviceIdentityProvider(); this.topicNameConverter = addressConverter; }
public static async Task<IMessagingServiceClient> CreateFromConnectionStringAsync(string deviceId, string connectionString, int connectionPoolSize, TimeSpan? connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { int maxPendingOutboundMessages = settings.MaxPendingOutboundMessages; var tcpSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only); var webSocketSettings = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only); webSocketSettings.PrefetchCount = tcpSettings.PrefetchCount = (uint)maxPendingOutboundMessages; if (connectionPoolSize > 0) { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings { MaxPoolSize = unchecked ((uint)connectionPoolSize), Pooling = connectionPoolSize > 0 }; if (connectionIdleTimeout.HasValue) { amqpConnectionPoolSettings.ConnectionIdleTimeout = connectionIdleTimeout.Value; } tcpSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; webSocketSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; } DeviceClient client = DeviceClient.CreateFromConnectionString(connectionString, new ITransportSettings[] { tcpSettings, webSocketSettings }); try { await client.OpenAsync(); } catch (IotHubException ex) { throw ComposeIotHubCommunicationException(ex); } return new IotHubClient(client, deviceId, settings, allocator, messageAddressConverter); }
public static Func <IDeviceIdentity, Task <IMessagingServiceClient> > PreparePoolFactory(string baseConnectionString, int connectionPoolSize, TimeSpan?connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { IotHubConnectionStringBuilder csb = IotHubConnectionStringBuilder.Create(baseConnectionString); Func <IDeviceIdentity, Task <IMessagingServiceClient> > mqttCommunicatorFactory = deviceIdentity => { var identity = (IotHubDeviceIdentity)deviceIdentity; csb.AuthenticationMethod = DeriveAuthenticationMethod(csb.AuthenticationMethod, identity); csb.HostName = identity.IotHubHostName; string connectionString = csb.ToString(); return(CreateFromConnectionStringAsync(identity.Id, connectionString, connectionPoolSize, connectionIdleTimeout, settings, allocator, messageAddressConverter)); }; return(mqttCommunicatorFactory); }
public static async Task <IMessagingServiceClient> CreateFromConnectionStringAsync(string deviceId, string connectionString, int connectionPoolSize, TimeSpan?connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { int maxPendingOutboundMessages = settings.MaxPendingOutboundMessages; var tcpSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only); var webSocketSettings = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only); webSocketSettings.PrefetchCount = tcpSettings.PrefetchCount = (uint)maxPendingOutboundMessages; if (connectionPoolSize > 0) { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings { MaxPoolSize = unchecked ((uint)connectionPoolSize), Pooling = connectionPoolSize > 0 }; if (connectionIdleTimeout.HasValue) { amqpConnectionPoolSettings.ConnectionIdleTimeout = connectionIdleTimeout.Value; } tcpSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; webSocketSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; } DeviceClient client = DeviceClient.CreateFromConnectionString(connectionString, new ITransportSettings[] { tcpSettings, webSocketSettings }); try { await client.OpenAsync(); } catch (IotHubException ex) { throw ComposeIotHubCommunicationException(ex); } return(new IotHubClient(client, deviceId, settings, allocator, messageAddressConverter)); }
public static async Task <IMessagingServiceClient> CreateFromX509CertificateAsync(string deviceId, string connectionString, int connectionPoolSize, TimeSpan?connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter, X509Certificate2 clientCertificate) { int maxPendingOutboundMessages = settings.MaxPendingOutboundMessages; var tcpSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only) { ClientCertificate = clientCertificate }; var webSocketSettings = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only) { ClientCertificate = clientCertificate }; // COE --> There is something in the settings that prevents this from working correctly //webSocketSettings.PrefetchCount = tcpSettings.PrefetchCount = (uint)maxPendingOutboundMessages; //if (connectionPoolSize > 0) //{ // var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings // { // MaxPoolSize = unchecked((uint)connectionPoolSize), // Pooling = connectionPoolSize > 0 // }; // if (connectionIdleTimeout.HasValue) // { // amqpConnectionPoolSettings.ConnectionIdleTimeout = connectionIdleTimeout.Value; // } // tcpSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; // webSocketSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; //} DeviceClient client = DeviceClient.CreateFromConnectionString(connectionString, new ITransportSettings[] { tcpSettings, webSocketSettings }); try { await client.OpenAsync(); } catch (IotHubException ex) { throw ComposeIotHubCommunicationException(ex); } return(new IotHubClient(client, deviceId, settings, allocator, messageAddressConverter)); }