public OrderAcceptedHandler(ChaosGenerator chaos)
 {
     this.chaos = chaos;
 }
Exemplo n.º 2
0
 public OrderShippedHandler(ChaosGenerator chaos)
 {
     this.chaos = chaos;
 }
Exemplo n.º 3
0
    static async Task Main()
    {
        var connectionString = @"Data Source=.\SqlExpress;Initial Catalog=nservicebus;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";

        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Sales";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();
        var          endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.SqlServerTransportAdapter.Sales");

        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();
        var routing   = transport.Routing();

        routing.RegisterPublisher(typeof(OrderShipped),
                                  "Samples.ServiceControl.SqlServerTransportAdapter.Shipping");
        transport.ConnectionString(connectionString);

        SqlHelper.EnsureDatabaseExists(connectionString);
        SqlHelper.CreateSchema(connectionString, "sales");
        SqlHelper.CreateSchema(connectionString, "adapter");

        #region SalesSchema

        //Use custom schema shipping for this endpoint
        transport.DefaultSchema("sales");

        //Configure schemas for ServiceControl queues to point to adapter
        transport.UseSchemaForQueue("audit", "adapter");
        transport.UseSchemaForQueue("error", "adapter");
        transport.UseSchemaForQueue("Particular.ServiceControl", "adapter");

        //Configure schema for shipping endpoint so that the subscribe message is sent to the correct address
        transport.UseSchemaForQueue(
            queueName: "Samples.ServiceControl.SqlServerTransportAdapter.Shipping",
            schema: "shipping");

        #endregion

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();
        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));
        recoverability.DisableLegacyRetriesSatellite();

        var conventions = endpointConfiguration.Conventions();
        conventions.DefiningEventsAs(t => t == typeof(OrderAccepted) || t == typeof(OrderShipped));

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to generate order");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var orderId        = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var orderSubmitted = new OrderAccepted
                {
                    OrderId = orderId,
                    Value   = random.Next(100)
                };
                await endpointInstance.Publish(orderSubmitted)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine("Failure simulation is now turned " + (chaos.IsFailing ? "on" : "off"));
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
 public SalesMessageHandler(ChaosGenerator chaos)
 {
     this.chaos = chaos;
 }
Exemplo n.º 5
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqsTransportAdapter.Endpoint";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();
        var          endpointConfiguration = new EndpointConfiguration(
            "Samples.ServiceControl.SqsTransportAdapter.Endpoint");

        endpointConfiguration.SendHeartbeatTo("Particular.ServiceControl");

        var transport = endpointConfiguration.UseTransport <SqsTransport>();

        transport.S3("bucketname", "my/key/prefix");

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();

        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();

        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to send a message");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var id      = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var message = new MyMessage
                {
                    Id = id,
                };
                await endpointInstance.SendLocal(message)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine("Failure simulation is now turned " + (chaos.IsFailing ? "on" : "off"));
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 6
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.RabbitMQAdapter.Shipping";

        #region ShippingConfiguration

        var endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.RabbitMQAdapter.Shipping");

        var transport = endpointConfiguration.UseTransport <RabbitMQTransport>();
        transport.ConnectionString("host=localhost");
        transport.DelayedDelivery().DisableTimeoutManager();

        transport.UseDirectRoutingTopology();

        endpointConfiguration.SendFailedMessagesTo("adapter_error");
        endpointConfiguration.AuditProcessedMessagesTo("adapter_audit");
        endpointConfiguration.HeartbeatPlugin("adapter_Particular.ServiceControl");

        #endregion

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();
        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(
            customizations: delayed =>
        {
            delayed.NumberOfRetries(0);
        });
        recoverability.DisableLegacyRetriesSatellite();
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                ConsoleHelper.ToggleTitle();
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 7
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Sales";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();
        var          endpointConfiguration = new EndpointConfiguration(
            "Samples.ServiceControl.SqlServerTransportAdapter.Sales");

        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();
        var routing   = transport.Routing();

        routing.RegisterPublisher(typeof(OrderShipped),
                                  "Samples.ServiceControl.SqlServerTransportAdapter.Shipping");
#pragma warning disable 618
        transport.EnableLegacyMultiInstanceMode(Connections.GetConnection);
#pragma warning restore 618

        SqlHelper.EnsureDatabaseExists(Connections.Sales);

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();
        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));
        recoverability.DisableLegacyRetriesSatellite();

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to generate order");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var orderId        = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var orderSubmitted = new OrderAccepted
                {
                    OrderId = orderId,
                    Value   = random.Next(100)
                };
                await endpointInstance.Publish(orderSubmitted)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine("Failure simulation is now turned " + (chaos.IsFailing ? "on" : "off"));
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 8
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.ASQAdapter.Shipping";
        var endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.ASQAdapter.Shipping");

        var transport        = endpointConfiguration.UseTransport <AzureStorageQueueTransport>();
        var connectionString = Environment.GetEnvironmentVariable("AzureStorageQueue.ConnectionString.Endpoints");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read 'AzureStorageQueue.ConnectionString.Endpoints' environment variable. Check sample prerequisites.");
        }

        transport.ConnectionString(connectionString);
        transport.UseAccountAliasesInsteadOfConnectionStrings();
        transport.DefaultAccountAlias("storage_account");

        // Required to address https://github.com/Particular/NServiceBus.AzureStorageQueues/issues/308
        transport.AccountRouting().AddAccount("storage_account", connectionString);

        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.UseSerialization <NewtonsoftSerializer>();

        var chaos = new ChaosGenerator();

        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();

        recoverability.Failed(
            customizations: retryFailedSettings =>
        {
            retryFailedSettings.HeaderCustomization(
                customization: headers =>
            {
                headers[AdapterSpecificHeaders.OriginalStorageAccountAlias] = "storage_account";
            });
        });
        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(
            customizations: delayed =>
        {
            delayed.NumberOfRetries(0);
        });
        recoverability.DisableLegacyRetriesSatellite();

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.HeartbeatPlugin("Particular.ServiceControl");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                ConsoleHelper.ToggleTitle();
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 9
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.ASBAdapter.Shipping";
        var endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.ASBAdapter.Shipping");

#pragma warning disable 618
        var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>();
#pragma warning restore 618
        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString.2");
        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read 'AzureServiceBus.ConnectionString.2' environment variable. Check sample prerequisites.");
        }

        var salesConnectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString.1");
        if (string.IsNullOrWhiteSpace(salesConnectionString))
        {
            throw new Exception("Could not read 'AzureServiceBus.ConnectionString.1' environment variable. Check sample prerequisites.");
        }
        transport.ConnectionString(connectionString);
        transport.DefaultNamespaceAlias("shipping");
        transport.UseNamespaceAliasesInsteadOfConnectionStrings();
        var routing = transport.NamespaceRouting();
        routing.AddNamespace("sales", salesConnectionString);
        transport.UseForwardingTopology();
        transport.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream);
        transport.Composition().UseStrategy <HierarchyComposition>().PathGenerator(path => "scadapter/");

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        var recoverability = endpointConfiguration.Recoverability();
        recoverability.Failed(
            customizations: retryFailedSettings =>
        {
            retryFailedSettings.HeaderCustomization(
                customization: headers =>
            {
                headers[AdapterSpecificHeaders.OriginalNamespace] = "shipping";
            });
        });
        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(
            customizations: delayed =>
        {
            delayed.NumberOfRetries(0);
        });

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.SendHeartbeatTo("Particular.ServiceControl");
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UseSerialization <NewtonsoftSerializer>();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                ConsoleHelper.ToggleTitle();
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 10
0
    static void Main()
    {
        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Shipping";
        var endpointConfiguration = new BusConfiguration();

        endpointConfiguration.EndpointName("Samples.ServiceControl.SqlServerTransportAdapter.Shipping");

        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();

        transport.ConnectionString(@"Data Source=.\SqlExpress;Initial Catalog=nservicebus;Integrated Security=True;Max Pool Size=100;Min Pool Size=10");

        #region SchemaV5

        //Use custom schema shipping for this endpoint
        transport.DefaultSchema("shipping");

        transport.UseSpecificConnectionInformation(
            //Configure schema for sales endpoint so that the subscribe message is sent to the correct address
            EndpointConnectionInfo.For("Samples.ServiceControl.SqlServerTransportAdapter.Sales").UseSchema("sales"),
            //Configure schemas for ServiceControl queues to point to the adapter
            EndpointConnectionInfo.For("audit").UseSchema("adapter"),
            EndpointConnectionInfo.For("error").UseSchema("adapter"),
            EndpointConnectionInfo.For("Particular.ServiceControl").UseSchema("adapter")
            );

        #endregion

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        endpointConfiguration.DisableFeature <SecondLevelRetries>();

        var conventions = endpointConfiguration.Conventions();
        conventions.DefiningEventsAs(t => t == typeof(OrderAccepted) || t == typeof(OrderShipped));

        endpointConfiguration.EnableInstallers();

        using (var endpointInstance = Bus.Create(endpointConfiguration).Start())
        {
            Console.WriteLine("Press enter to exit");
            Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
            while (true)
            {
                var key = Console.ReadKey();
                Console.WriteLine();
                if (key.Key == ConsoleKey.Enter)
                {
                    break;
                }
                var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
                if (lowerInvariant == 'f')
                {
                    chaos.IsFailing = !chaos.IsFailing;
                    Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                }
            }
        }
    }
Exemplo n.º 11
0
    static async Task AsyncMain()
    {
        Console.Title = "Samples.ServiceControl.RabbitMQAdapter.Sales";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();

        #region SalesConfiguration

        var endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.RabbitMQAdapter.Sales");

        var transport = endpointConfiguration.UseTransport <RabbitMQTransport>();
        transport.ConnectionString("host=localhost");
        transport.UseDirectRoutingTopology();

        endpointConfiguration.SendFailedMessagesTo("adapter_error");
        endpointConfiguration.AuditProcessedMessagesTo("adapter_audit");

        #endregion

        var recoverability = endpointConfiguration.Recoverability();

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));
        recoverability.DisableLegacyRetriesSatellite();


        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to generate order");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var orderId   = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var shipOrder = new ShipOrder
                {
                    OrderId = orderId,
                    Value   = random.Next(100)
                };
                var sendOptions = new SendOptions();
                sendOptions.SetDestination("Samples.ServiceControl.RabbitMQAdapter.Shipping");
                await endpointInstance.Send(shipOrder, sendOptions)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                ConsoleHelper.ToggleTitle();
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 12
0
 public ShipOrderHandler(ChaosGenerator chaos)
 {
     this.chaos = chaos;
 }
Exemplo n.º 13
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.ASBAdapter.Sales";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();
        var          endpointConfiguration = new EndpointConfiguration("Samples.ServiceControl.ASBAdapter.Sales");

        var transport        = endpointConfiguration.UseTransport <AzureServiceBusTransport>();
        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString.1");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read 'AzureServiceBus.ConnectionString.1' environment variable. Check sample prerequisites.");
        }
        var shippingConnectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString.2");

        if (string.IsNullOrWhiteSpace(shippingConnectionString))
        {
            throw new Exception("Could not read 'AzureServiceBus.ConnectionString.2' environment variable. Check sample prerequisites.");
        }
        transport.ConnectionString(connectionString);

        #region FeaturesUnsuportedBySC

        transport.UseNamespaceAliasesInsteadOfConnectionStrings();
        transport.DefaultNamespaceAlias("sales");
        var routing = transport.NamespaceRouting();
        routing.AddNamespace("shipping", shippingConnectionString);
        transport.UseForwardingTopology();
        transport.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream);
        var composition = transport.Composition();
        composition.UseStrategy <HierarchyComposition>()
        .PathGenerator(path => "scadapter/");

        #endregion

        var recoverability = endpointConfiguration.Recoverability();

        #region NamespaceAlias

        recoverability.Failed(
            customizations: settings =>
        {
            settings.HeaderCustomization(
                customization: headers =>
            {
                headers[AdapterSpecificHeaders.OriginalNamespace] = "sales";
            });
        });

        #endregion

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        recoverability.Immediate(
            customizations: immediate =>
        {
            immediate.NumberOfRetries(0);
        });
        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));
        recoverability.DisableLegacyRetriesSatellite();

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to generate order");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var orderId   = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var shipOrder = new ShipOrder
                {
                    OrderId = orderId,
                    Value   = random.Next(100)
                };
                var sendOptions = new SendOptions();
                sendOptions.SetDestination("Samples.ServiceControl.ASBAdapter.Shipping@shipping");
                await endpointInstance.Send(shipOrder, sendOptions)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine($"Failure simulation is now turned {(chaos.IsFailing ? "on" : "off")}");
                ConsoleHelper.ToggleTitle();
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 14
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.MixedTransportAdapter.Shipping";
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVXYZ";
        var          random  = new Random();
        var          endpointConfiguration = new EndpointConfiguration(
            "Samples.ServiceControl.MixedTransportAdapter.Shipping");

        var connection = @"Data Source=.\SqlExpress;Initial Catalog=shipping;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";

        var transport = endpointConfiguration.UseTransport <SqlServerTransport>()
                        .ConnectionString(connection);

        SqlHelper.EnsureDatabaseExists(connection);

        endpointConfiguration.UsePersistence <InMemoryPersistence>();

        var chaos = new ChaosGenerator();

        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent(() => chaos, DependencyLifecycle.SingleInstance);
        });

        endpointConfiguration.Recoverability()
        .Immediate(immediate => immediate.NumberOfRetries(0))
        .Delayed(delayed => delayed.NumberOfRetries(0));

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.SendHeartbeatTo("Particular.ServiceControl");
        endpointConfiguration.EnableInstallers();

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

        Console.WriteLine("Press enter to exit");
        Console.WriteLine("Press 'o' to send a message");
        Console.WriteLine("Press 'f' to toggle simulating of message processing failure");
        while (true)
        {
            var key = Console.ReadKey();
            Console.WriteLine();
            if (key.Key == ConsoleKey.Enter)
            {
                break;
            }
            var lowerInvariant = char.ToLowerInvariant(key.KeyChar);
            if (lowerInvariant == 'o')
            {
                var id      = new string(Enumerable.Range(0, 4).Select(x => letters[random.Next(letters.Length)]).ToArray());
                var message = new ShippingMessage
                {
                    Id = id,
                };
                await endpointInstance.SendLocal(message)
                .ConfigureAwait(false);
            }
            if (lowerInvariant == 'f')
            {
                chaos.IsFailing = !chaos.IsFailing;
                Console.WriteLine("Failure simulation is now turned " + (chaos.IsFailing ? "on" : "off"));
            }
        }
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
 public OrderAcceptedHandler(ChaosGenerator chaos, IBus bus)
 {
     this.chaos = chaos;
     this.bus   = bus;
 }