示例#1
0
    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);
    }
示例#2
0
    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;
            }
        }
    }
示例#3
0
    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;
            }
        }
    }
示例#4
0
    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);
    }