public static async Task <Message> ProcessManagementRequestAsync(Message message, ManagementRequestProcessor processor) { ContainerHost host = Open(); try { host.RegisterRequestProcessor("$management", processor); Connection connection = await host.ConnectAsync(); var session = new Session(connection); try { return(await session.SendControlRequestAsync("$management", message)); } finally { await session.CloseAsync(); await connection.CloseAsync(); } } finally { host.Close(); } }
public static async Task <IDictionary <string, object> > ProcessCbsRequestAsync(string messageId, CbsRequestProcessor processor) { var responseProperties = new Dictionary <string, object>(); ContainerHost host = Open(); try { host.RegisterRequestProcessor("$cbs", processor); Connection connection = await host.ConnectAsync(); var session = new Session(connection); try { Message response = await session.SendCbsRequestAsync(messageId); responseProperties["CorrelationId"] = response.Properties.CorrelationId; responseProperties["status-code"] = response.ApplicationProperties["status-code"]; } finally { await session.CloseAsync(); await connection.CloseAsync(); } } finally { host.Close(); } return(responseProperties); }
public static async Task <Session> OpenAndLinkProcessorAsync(ILinkProcessor linkProcessor) { ContainerHost host = Open(); host.RegisterLinkProcessor(linkProcessor); Connection connection = await host.ConnectAsync(); var session = new Session(connection); session.AddClosedCallback((_, __) => host.Close()); return(session); }
public static async Task <Connection> ConnectAndAttachAsync(this ContainerHost host, int nSessions = 1) { Connection connection = await host.ConnectAsync(); try { IEnumerable <SenderLink> links = Enumerable .Range(1, nSessions) .Select(i => new SenderLink(new Session(connection), "A" + i, "A" + i)); Parallel.ForEach(links, link => link.Send(new Message("msg1"), TimeSpan.FromMilliseconds(500))); } catch { // ignore } return(connection); }