public async Task <AmqpIoTConnection> OpenConnectionAsync(TimeSpan timeout) { Logging.Enter(this, timeout, $"{nameof(OpenConnectionAsync)}"); var amqpTransportProvider = new AmqpTransportProvider(); amqpTransportProvider.Versions.Add(s_amqpVersion_1_0_0); var amqpSettings = new AmqpSettings(); 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); } _amqpIotTransport = new AmqpIoTTransport(amqpSettings, _amqpTransportSettings, _hostName, s_disableServerCertificateValidation); TransportBase transportBase = await _amqpIotTransport.InitializeAsync(timeout).ConfigureAwait(false); try { var amqpConnection = new AmqpConnection(transportBase, amqpSettings, amqpConnectionSettings); var amqpIoTConnection = new AmqpIoTConnection(amqpConnection); amqpConnection.Closed += amqpIoTConnection.AmqpConnectionClosed; await amqpConnection.OpenAsync(timeout).ConfigureAwait(false); Logging.Exit(this, timeout, $"{nameof(OpenConnectionAsync)}"); return(amqpIoTConnection); } catch (Exception ex) when(!ex.IsFatal()) { transportBase?.Close(); _amqpIotTransport?.Dispose(); throw; } finally { Logging.Exit(this, $"{nameof(OpenConnectionAsync)}"); } }
public void Dispose() { _amqpIotTransport?.Dispose(); _amqpIotTransport = null; }