internal AmqpConnector(AmqpTransportSettings amqpTransportSettings, string hostName) { AmqpTransportSettings = amqpTransportSettings; AmqpSettings = new AmqpSettings(); var amqpTransportProvider = new AmqpTransportProvider(); amqpTransportProvider.Versions.Add(amqpVersion_1_0_0); AmqpSettings.TransportProviders.Add(amqpTransportProvider); AmqpConnectionSettings = new AmqpConnectionSettings() { MaxFrameSize = AmqpConstants.DefaultMaxFrameSize, ContainerId = CommonResources.GetNewStringGuid(), HostName = hostName }; var tcpTransportSettings = new TcpTransportSettings() { Host = hostName, Port = AmqpConstants.DefaultSecurePort }; TlsTransportSettings = new TlsTransportSettings(tcpTransportSettings) { TargetHost = hostName, Certificate = null, CertificateValidationCallback = AmqpTransportSettings.RemoteCertificateValidationCallback ?? OnRemoteCertificateValidation }; if (AmqpTransportSettings.ClientCertificate != null) { TlsTransportSettings.Certificate = AmqpTransportSettings.ClientCertificate; } }
public async Task <AmqpIoTConnection> OpenConnectionAsync(TimeSpan timeout) { if (Logging.IsEnabled) { Logging.Enter(this, timeout, $"{nameof(OpenConnectionAsync)}"); } var amqpSettings = new AmqpSettings(); var amqpTransportProvider = new AmqpTransportProvider(); amqpTransportProvider.Versions.Add(s_amqpVersion_1_0_0); amqpSettings.TransportProviders.Add(amqpTransportProvider); var amqpConnectionSettings = new AmqpConnectionSettings() { MaxFrameSize = AmqpConstants.DefaultMaxFrameSize, ContainerId = CommonResources.GetNewStringGuid(), HostName = _hostName }; TimeSpan idleTimeout = _amqpTransportSettings.IdleTimeout; if (idleTimeout != null) { amqpConnectionSettings.IdleTimeOut = Convert.ToUInt32(idleTimeout.TotalMilliseconds); } var amqpIoTTransport = new AmqpIoTTransport(amqpSettings, _amqpTransportSettings, _hostName, s_disableServerCertificateValidation); TransportBase transportBase = await amqpIoTTransport.InitializeAsync(timeout).ConfigureAwait(false); try { var amqpConnection = new AmqpConnection(transportBase, amqpSettings, amqpConnectionSettings); AmqpIoTConnection amqpIoTConnection = new AmqpIoTConnection(amqpConnection); amqpConnection.Closed += amqpIoTConnection.AmqpConnectionClosed; await amqpConnection.OpenAsync(timeout).ConfigureAwait(false); if (Logging.IsEnabled) { Logging.Exit(this, timeout, $"{nameof(OpenConnectionAsync)}"); } return(amqpIoTConnection); } catch (Exception e) when(!e.IsFatal()) { transportBase?.Close(); throw; } finally { if (Logging.IsEnabled) { Logging.Exit(this, $"{nameof(OpenConnectionAsync)}"); } } }
internal static async Task <ReceivingAmqpLink> OpenReceivingAmqpLinkAsync( DeviceIdentity deviceIdentity, AmqpSession amqpSession, byte?senderSettleMode, byte?receiverSettleMode, string deviceTemplate, string moduleTemplate, string linkSuffix, string CorrelationId, TimeSpan timeout ) { if (Logging.IsEnabled) { Logging.Enter(typeof(AmqpLinkHelper), deviceIdentity, $"{nameof(OpenReceivingAmqpLinkAsync)}"); } uint prefetchCount = deviceIdentity.AmqpTransportSettings.PrefetchCount; AmqpLinkSettings amqpLinkSettings = new AmqpLinkSettings { LinkName = CommonResources.GetNewStringGuid(linkSuffix), Role = true, TotalLinkCredit = prefetchCount, AutoSendFlow = prefetchCount > 0, Source = new Source() { Address = BuildLinkAddress(deviceIdentity, deviceTemplate, moduleTemplate) }, Target = new Target() { Address = deviceIdentity.IotHubConnectionString.DeviceId } }; amqpLinkSettings.SndSettleMode = senderSettleMode; amqpLinkSettings.RcvSettleMode = receiverSettleMode; amqpLinkSettings.AddProperty(IotHubAmqpProperty.TimeoutName, timeout.TotalMilliseconds); amqpLinkSettings.AddProperty(IotHubAmqpProperty.ClientVersion, deviceIdentity.ProductInfo.ToString()); amqpLinkSettings.AddProperty(IotHubAmqpProperty.ApiVersion, ClientApiVersionHelper.ApiVersionString); if (CorrelationId != null) { amqpLinkSettings.AddProperty(IotHubAmqpProperty.ChannelCorrelationId, CorrelationId); } ReceivingAmqpLink receivingLink = new ReceivingAmqpLink(amqpLinkSettings); receivingLink.AttachTo(amqpSession); await receivingLink.OpenAsync(timeout).ConfigureAwait(false); if (Logging.IsEnabled) { Logging.Exit(typeof(AmqpLinkHelper), deviceIdentity, $"{nameof(OpenReceivingAmqpLinkAsync)}"); } return(receivingLink); }
private static async Task <AmqpIoTSendingLink> OpenSendingAmqpLinkAsync( DeviceIdentity deviceIdentity, AmqpSession amqpSession, byte?senderSettleMode, byte?receiverSettleMode, string deviceTemplate, string moduleTemplate, string linkSuffix, string CorrelationId, TimeSpan timeout ) { if (Logging.IsEnabled) { Logging.Enter(typeof(AmqpIoTSession), deviceIdentity, $"{nameof(OpenSendingAmqpLinkAsync)}"); } AmqpLinkSettings amqpLinkSettings = new AmqpLinkSettings { LinkName = CommonResources.GetNewStringGuid(linkSuffix), Role = false, InitialDeliveryCount = 0, Target = new Target() { Address = BuildLinkAddress(deviceIdentity, deviceTemplate, moduleTemplate) }, Source = new Source() { Address = deviceIdentity.IotHubConnectionString.DeviceId } }; amqpLinkSettings.SndSettleMode = senderSettleMode; amqpLinkSettings.RcvSettleMode = receiverSettleMode; amqpLinkSettings.AddProperty(AmqpIoTErrorAdapter.TimeoutName, timeout.TotalMilliseconds); amqpLinkSettings.AddProperty(AmqpIoTErrorAdapter.ClientVersion, deviceIdentity.ProductInfo.ToString()); amqpLinkSettings.AddProperty(AmqpIoTErrorAdapter.ApiVersion, ClientApiVersionHelper.ApiVersionString); if (CorrelationId != null) { amqpLinkSettings.AddProperty(AmqpIoTErrorAdapter.ChannelCorrelationId, CorrelationId); } SendingAmqpLink sendingLink = new SendingAmqpLink(amqpLinkSettings); sendingLink.AttachTo(amqpSession); await sendingLink.OpenAsync(timeout).ConfigureAwait(false); if (Logging.IsEnabled) { Logging.Exit(typeof(AmqpIoTSession), deviceIdentity, $"{nameof(OpenSendingAmqpLinkAsync)}"); } return(new AmqpIoTSendingLink(sendingLink)); }
internal AmqpIoTConnection(AmqpTransportSettings amqpTransportSettings, string hostName, bool disableServerCertificateValidation) { _amqpTransportSettings = amqpTransportSettings; _amqpSettings = new AmqpSettings(); var amqpTransportProvider = new AmqpTransportProvider(); amqpTransportProvider.Versions.Add(amqpVersion_1_0_0); _amqpSettings.TransportProviders.Add(amqpTransportProvider); _amqpConnectionSettings = new AmqpConnectionSettings() { MaxFrameSize = AmqpConstants.DefaultMaxFrameSize, ContainerId = CommonResources.GetNewStringGuid(), HostName = hostName }; _amqpIoTTransport = new AmqpIoTTransport(_amqpSettings, _amqpTransportSettings, hostName, disableServerCertificateValidation); }