static async Task Main(string[] args) { Console.Title = "Samples.SessionFilter.Sender"; var endpointConfiguration = new EndpointConfiguration("Samples.SessionFilter.Sender"); endpointConfiguration.UsePersistence <LearningPersistence>(); var transport = endpointConfiguration.UseTransport <LearningTransport>(); transport.Routing().RouteToEndpoint( typeof(SomeMessage), "Samples.SessionFilter.Receiver" ); #region add-filter-behavior var sessionKeyProvider = new RotatingSessionKeyProvider(); endpointConfiguration.ApplySessionFilter(sessionKeyProvider); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); #endregion await MainLoop(endpointInstance, sessionKeyProvider) .ConfigureAwait(false); await endpointInstance.Stop() .ConfigureAwait(false); }
static async Task MainLoop(IEndpointInstance endpoint, RotatingSessionKeyProvider sessionKeyProvider) { PrintMenu(sessionKeyProvider); var index = 1; while (true) { switch (Console.ReadKey(true).Key) { case ConsoleKey.C: sessionKeyProvider.NextKey(); PrintMenu(sessionKeyProvider); break; case ConsoleKey.Escape: return; default: await endpoint.Send(new SomeMessage { Counter = index }) .ConfigureAwait(false); Console.WriteLine($"Sent message {index++}"); break; } } }
static void MainLoop(RotatingSessionKeyProvider sessionKeyProvider) { PrintMenu(sessionKeyProvider); while (true) { switch (Console.ReadKey(true).Key) { case ConsoleKey.C: sessionKeyProvider.NextKey(); PrintMenu(sessionKeyProvider); break; case ConsoleKey.Escape: return; } } }
static async Task Main(string[] args) { Console.Title = "Samples.SessionFilter.Receiver"; var endpointConfiguration = new EndpointConfiguration("Samples.SessionFilter.Receiver"); endpointConfiguration.UsePersistence <LearningPersistence>(); var transport = endpointConfiguration.UseTransport <LearningTransport>(); var sessionKeyProvider = new RotatingSessionKeyProvider(); endpointConfiguration.ApplySessionFilter(sessionKeyProvider); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); MainLoop(sessionKeyProvider); await endpointInstance.Stop() .ConfigureAwait(false); }