/// <summary> /// Creates an AMQP connection for a given scope. /// </summary> /// /// <param name="amqpVersion">The version of AMQP to use for the connection.</param> /// <param name="serviceEndpoint">The endpoint for the Event Hubs service to which the scope is associated.</param> /// <param name="transportType">The type of transport to use for communication.</param> /// <param name="proxy">The proxy, if any, to use for communication.</param> /// <param name="scopeIdentifier">The unique identifier for the associated scope.</param> /// <param name="timeout">The timeout to consider when creating the connection.</param> /// /// <returns>An AMQP connection that may be used for communicating with the Event Hubs service.</returns> /// protected virtual async Task <AmqpConnection> CreateAndOpenConnectionAsync(Version amqpVersion, Uri serviceEndpoint, TransportType transportType, IWebProxy proxy, string scopeIdentifier, TimeSpan timeout) { var hostName = serviceEndpoint.Host; AmqpSettings amqpSettings = CreateAmpqSettings(AmqpVersion); AmqpConnectionSettings connectionSetings = CreateAmqpConnectionSettings(hostName, scopeIdentifier); TransportSettings transportSettings = transportType.IsWebSocketTransport() ? CreateTransportSettingsForWebSockets(hostName, proxy) : CreateTransportSettingsforTcp(hostName, serviceEndpoint.Port); // Create and open the connection, respecting the timeout constraint // that was received. var stopWatch = Stopwatch.StartNew(); var initiator = new AmqpTransportInitiator(amqpSettings, transportSettings); TransportBase transport = await initiator.ConnectTaskAsync(timeout).ConfigureAwait(false); var connection = new AmqpConnection(transport, amqpSettings, connectionSetings); await OpenAmqpObjectAsync(connection, timeout.CalculateRemaining(stopWatch.Elapsed)).ConfigureAwait(false); stopWatch.Stop(); // Create the CBS link that will be used for authorization. The act of creating the link will associate // it with the connection. new AmqpCbsLink(connection); // When the connection is closed, close each of the links associated with it. EventHandler closeHandler = null; closeHandler = (snd, args) => { foreach (var link in ActiveLinks.Keys) { link.SafeClose(); } connection.Closed -= closeHandler; }; connection.Closed += closeHandler; return(connection); }
/// <summary> /// Creates an AMQP connection for a given scope. /// </summary> /// /// <param name="amqpVersion">The version of AMQP to use for the connection.</param> /// <param name="serviceEndpoint">The endpoint for the Event Hubs service to which the scope is associated.</param> /// <param name="transportType">The type of transport to use for communication.</param> /// <param name="proxy">The proxy, if any, to use for communication.</param> /// <param name="scopeIdentifier">The unique identifier for the associated scope.</param> /// <param name="timeout">The timeout to consider when creating the connection.</param> /// /// <returns>An AMQP connection that may be used for communicating with the Event Hubs service.</returns> /// protected virtual async Task <AmqpConnection> CreateConnectionAsync(Version amqpVersion, Uri serviceEndpoint, TransportType transportType, IWebProxy proxy, string scopeIdentifier, TimeSpan timeout) { var hostName = serviceEndpoint.Host; var amqpSettings = CreateAmpqSettings(AmqpVersion); var connectionSetings = CreateAmqpConnectionSettings(hostName, scopeIdentifier); var transportSettings = transportType.IsWebSocketTransport() ? CreateTransportSettingsForWebSockets(hostName, proxy) : CreateTransportSettingsforTcp(hostName, serviceEndpoint.Port); // Create and open the connection, respecting the timeout constraint // that was received. var stopWatch = Stopwatch.StartNew(); var initiator = new AmqpTransportInitiator(amqpSettings, transportSettings); var transport = await initiator.ConnectTaskAsync(timeout).ConfigureAwait(false); var connection = new AmqpConnection(transport, amqpSettings, connectionSetings); await connection.OpenAsync(timeout.CalculateRemaining(stopWatch.Elapsed)).ConfigureAwait(false); stopWatch.Stop(); // Create the CBS link that will be used for authorization and ensure that it is associated // with the connection. var cbsLink = new AmqpCbsLink(connection); // TODO (pri2 // squire): // The act of creating the link should ensure that it is added to the connection. Unsure // of why this additional check was in the track one code. Investigate and either // document or remove. if (!connection.Extensions.Contains(typeof(AmqpCbsLink))) { connection.Extensions.Add(cbsLink); } return(connection); }
public void IsWebSocketTransportRecognizesSocketTransports(TransportType transportType, bool expectedResult) { Assert.That(transportType.IsWebSocketTransport(), Is.EqualTo(expectedResult)); }