Пример #1
0
    static void Main()
    {
        Console.Title = "Samples.AuditFilter";
        LogManager.Use <DefaultFactory>()
        .Level(LogLevel.Info);
        var busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.AuditFilter");
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        using (var bus = Bus.Create(busConfiguration).Start())
        {
            var auditThisMessage = new AuditThisMessage
            {
                Content = "See you in the audit queue!"
            };
            bus.SendLocal(auditThisMessage);

            var doNotAuditThisMessage = new DoNotAuditThisMessage
            {
                Content = "Don't look for me!"
            };
            bus.SendLocal(doNotAuditThisMessage);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
Пример #2
0
    static async Task AsyncRun()
    {
        Console.Title = "Samples.AuditFilter";
        var endpointConfiguration = new EndpointConfiguration("Samples.AuditFilter");

        endpointConfiguration.UseSerialization <JsonSerializer>();
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.SendFailedMessagesTo("error");

        #region addFilterBehaviors

        endpointConfiguration.AuditProcessedMessagesTo("Samples.AuditFilter.Audit");

        var pipeline = endpointConfiguration.Pipeline;
        pipeline.Register(
            stepId: "AuditFilter.Filter",
            behavior: typeof(AuditFilterBehavior),
            description: "prevents marked messages from being forwarded to the audit queue");
        pipeline.Register(
            stepId: "AuditFilter.Rules",
            behavior: typeof(AuditRulesBehavior),
            description: "checks whether a message should be forwarded to the audit queue");
        pipeline.Register(
            stepId: "AuditFilter.Context",
            behavior: typeof(AuditFilterContextBehavior),
            description: "adds a shared state for the rules and filter behaviors");

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        #endregion

        try
        {
            var auditThisMessage = new AuditThisMessage
            {
                Content = "See you in the audit queue!"
            };
            await endpointInstance.SendLocal(auditThisMessage)
            .ConfigureAwait(false);

            var doNotAuditThisMessage = new DoNotAuditThisMessage
            {
                Content = "Don't look for me!"
            };
            await endpointInstance.SendLocal(doNotAuditThisMessage)
            .ConfigureAwait(false);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
    }
Пример #3
0
    static async Task Main()
    {
        //required to prevent possible occurrence of .NET Core issue https://github.com/dotnet/coreclr/issues/12668
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");

        Console.Title = "Samples.AuditFilter";
        var endpointConfiguration = new EndpointConfiguration("Samples.AuditFilter");

        endpointConfiguration.UsePersistence <LearningPersistence>();
        endpointConfiguration.UseTransport <LearningTransport>();

        #region addFilterBehaviors

        endpointConfiguration.AuditProcessedMessagesTo("audit");

        var pipeline = endpointConfiguration.Pipeline;
        pipeline.Register(
            stepId: "AuditFilter.Filter",
            behavior: typeof(AuditFilterBehavior),
            description: "prevents marked messages from being forwarded to the audit queue");
        pipeline.Register(
            stepId: "AuditFilter.Rules",
            behavior: typeof(AuditRulesBehavior),
            description: "checks whether a message should be forwarded to the audit queue");
        pipeline.Register(
            stepId: "AuditFilter.Context",
            behavior: typeof(AuditFilterContextBehavior),
            description: "adds a shared state for the rules and filter behaviors");

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        #endregion

        var auditThisMessage = new AuditThisMessage
        {
            Content = "See you in the audit queue!"
        };
        await endpointInstance.SendLocal(auditThisMessage)
        .ConfigureAwait(false);

        var doNotAuditThisMessage = new DoNotAuditThisMessage
        {
            Content = "Don't look for me!"
        };
        await endpointInstance.SendLocal(doNotAuditThisMessage)
        .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }