public async Task Should_be_able_to_close_connection() { // first get a connection var connections = await managementClient.GetConnectionsAsync().ConfigureAwait(false); // then close it await managementClient.CloseConnectionAsync(connections.First()).ConfigureAwait(false); }
public async Task Should_get_connections() { foreach (var connection in await managementClient.GetConnectionsAsync().ConfigureAwait(false)) { Console.Out.WriteLine("connection.Name = {0}", connection.Name); var clientProperties = connection.ClientProperties; Console.WriteLine("User:\t{0}", clientProperties.User); Console.WriteLine("Application:\t{0}", clientProperties.Application); Console.WriteLine("ClientApi:\t{0}", clientProperties.ClientApi); Console.WriteLine("ApplicationLocation:\t{0}", clientProperties.ApplicationLocation); Console.WriteLine("Connected:\t{0}", clientProperties.Connected); Console.WriteLine("EasynetqVersion:\t{0}", clientProperties.EasynetqVersion); Console.WriteLine("MachineName:\t{0}", clientProperties.MachineName); //Test the dynamic nature Console.WriteLine("Copyright:\t{0}", ((dynamic)clientProperties).Copyright); } }
/// <summary> /// A list of all open connections. /// </summary> /// <param name="source"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static IReadOnlyList <Connection> GetConnections( [NotNull] this IManagementClient source, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.GetConnectionsAsync(cancellationToken) .GetAwaiter() .GetResult()); }
public static async Task KillAllConnectionsAsync( this IManagementClient client, CancellationToken cancellationToken ) { // We need this crunch with loop because it seems that management plugin has some delay in showing info // and we could receive an empty list of connections even if connections are open var wasClosed = false; do { var connections = await client.GetConnectionsAsync(cancellationToken).ConfigureAwait(false); foreach (var connection in connections) { await client.CloseConnectionAsync(connection, cancellationToken).ConfigureAwait(false); wasClosed = true; } await Task.Delay(500, cancellationToken).ConfigureAwait(false); } while (!wasClosed); }