Exemplo n.º 1
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Adapter";
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, MsmqTransport>("ServiceControl.SqlServer.Adapter");

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            var connection = @"Data Source=.\SqlExpress;Initial Catalog=shipping;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";
            transport.ConnectionString(connection);
        });

        #endregion

#pragma warning restore 618

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 2
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Adapter";
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, SqlServerTransport>("ServiceControl.SqlServer.Adapter");
        #endregion

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            var connection = @"Data Source=.\SqlExpress;Initial Catalog=nservicebus;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";
            transport.ConnectionString(connection);
            transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);

            //Use custom schema
            transport.DefaultSchema("adapter");

            //Necessary to correctly route retried messages because
            //SQL Server transport 2.x did not include schema information in the address
            transport.UseSchemaForQueue(
                queueName: "Samples.ServiceControl.SqlServerTransportAdapter.Shipping",
                schema: "shipping");

            SqlHelper.EnsureDatabaseExists(connection);
            SqlHelper.CreateSchema(connection, "adapter");
        });

        #endregion

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            transport.ConnectionString(
                @"Data Source=.\SqlExpress;Initial Catalog=ServiceControl;Integrated Security=True;Max Pool Size=100;Min Pool Size=10");
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.SQL";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 3
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqsTransportAdapter.Adapter";
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqsTransport, MsmqTransport>("ServiceControl.SQS.Adapter");

        #endregion

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(transport =>
        {
            transport.S3("bucketname", "my/key/prefix");
        });

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            try
            {
                var adapterConfig = new TransportAdapterConfig <LearningTransport, LearningTransport>("TransportAdapter.ScAdapterService");

                adapterConfig.CustomizeEndpointTransport(t =>
                {
                    //TODO: Customize the endpoint-facing side of the adapter
                    //Use exactly the same settings as in regular endpoints
                });

                adapterConfig.CustomizeServiceControlTransport(t =>
                {
                    //TODO: Customize the ServiceControl-facing side of the adapter
                    //e.g. specify the same connection string as ServiceControl uses.
                });

                adapter = TransportAdapter.Create(adapterConfig);

                await adapter.Start();
            }
            catch (Exception exception)
            {
                FailFast("Failed to start", exception);
            }
        }
Exemplo n.º 5
0
    async Task AsyncOnStart()
    {
        try
        {
            var adapterConfig = new TransportAdapterConfig <LearningTransport, LearningTransport>("TransportAdapter.WindowsService");

            adapterConfig.CustomizeEndpointTransport(t =>
            {
                //TODO: Customize the endpoint-facing side of the adapter
                //Use exactly same settings as in regular endpoints
            });

            adapterConfig.CustomizeServiceControlTransport(t =>
            {
                //TODO: Customize the ServiceControl-facing side of the adapter
                //e.g. specify the same connection string as ServiceControl uses.
            });

            adapter = TransportAdapter.Create(adapterConfig);

            await adapter.Start().ConfigureAwait(false);
        }
        catch (Exception exception)
        {
            Exit("Failed to start", exception);
        }
    }
Exemplo n.º 6
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.RabbitMQAdapter.Adapter";
        #region AdapterTransport

        var transportAdapter =
            new TransportAdapterConfig <RabbitMQTransport, RabbitMQTransport>("ServiceControl.RabbitMQ.Adapter");

        transportAdapter.CustomizeServiceControlTransport(
            customization: transport =>
        {
            transport.ConnectionString("host=localhost");
            var delayedDelivery = transport.DelayedDelivery();

            transport.UseConventionalRoutingTopology();
        });

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapter.CustomizeEndpointTransport(
            customization: transport =>
        {
            transport.ConnectionString("host=localhost");
            var delayedDelivery = transport.DelayedDelivery();

            transport.UseDirectRoutingTopology();
        });

        #endregion

#pragma warning restore 618

        #region AdapterQueueConfiguration

        transportAdapter.EndpointSideErrorQueue   = "adapter_error";
        transportAdapter.EndpointSideAuditQueue   = "adapter_audit";
        transportAdapter.EndpointSideControlQueue = "adapter_Particular.ServiceControl";

        transportAdapter.ServiceControlSideErrorQueue   = "error";
        transportAdapter.ServiceControlSideAuditQueue   = "audit";
        transportAdapter.ServiceControlSideControlQueue = "Particular.ServiceControl";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapter);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 7
0
    static async Task AsyncMain()
    {
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, SqlServerTransport>("ServiceControl.SqlServer.Adapter");

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            transport.EnableLegacyMultiInstanceMode(Connections.GetConnection);
            //HACK: SQLServer expects this to be present. Will be solved in SQL 3.1
            var settings = transport.GetSettings();
            settings.Set <EndpointInstances>(new EndpointInstances());
        });

        #endregion

#pragma warning restore 618

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            var connection = @"Data Source=.\SqlExpress;Initial Catalog=ServiceControl;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";
            transport.ConnectionString(connection);
            //HACK: SQLServer expects this to be present. Will be solved in SQL 3.1
            var settings = transport.GetSettings();
            settings.Set <EndpointInstances>(new EndpointInstances());
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.SQL";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 8
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.SqlServerTransportAdapter.Adapter";
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, SqlServerTransport>("ServiceControl.SqlServer.Adapter");

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            transport.EnableLegacyMultiInstanceMode(Connections.GetConnection);

            SqlHelper.EnsureDatabaseExists(Connections.Adapter);
        });

        #endregion

#pragma warning restore 618

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            var connection = @"Data Source=.\SqlExpress;Initial Catalog=ServiceControl;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";
            transport.ConnectionString(connection);
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.SQL";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 9
0
        async Task Lifecycle()
        {
            #region Lifecycle

            var config = new TransportAdapterConfig <MyTransport, MyOtherTransport>("Adapter");

            var adapter = TransportAdapter.Create(config);

            //Starting up
            await adapter.Start().ConfigureAwait(false);

            //Shutting down
            await adapter.Stop().ConfigureAwait(false);

            #endregion
        }
Exemplo n.º 10
0
    static async Task AsyncMain()
    {
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, MsmqTransport>("ServiceControl.SqlServer.Adapter");

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            var connection = @"Data Source=.\SqlExpress;Initial Catalog=shipping;Integrated Security=True;Max Pool Size=100;Min Pool Size=10";
            transport.ConnectionString(connection);
            //HACK: SQLServer expects this to be present. Will be solved in SQL 3.1
            var settings = transport.GetSettings();
            settings.Set <EndpointInstances>(new EndpointInstances());
        });

        #endregion

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            //HACK: Latest MSMQ requires this setting. To be moved to the transport adapter core.
            var settings = transport.GetSettings();
            settings.Set("errorQueue", "poison");
        });

#pragma warning restore 618

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
        async Task AsyncOnStart()
        {
            const string catalogName = "ServiceControl";

            await SqlHelper.EnsureDatabaseExists(catalogName);

            var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, SqlServerTransport>(serviceName)
            {
                EndpointSideAuditQueue       = "audit",
                EndpointSideErrorQueue       = "error",
                ServiceControlSideAuditQueue = "audit_adapted",
                ServiceControlSideErrorQueue = "error_adapted"
            };

            transportAdapterConfig.CustomizeEndpointTransport(transport => transport.ConnectionString(SqlHelper.BuildCatalogConnectionString(catalogName)));

            transportAdapterConfig.CustomizeServiceControlTransport(transport => transport.ConnectionString(SqlHelper.BuildCatalogConnectionString(catalogName)));

            transportAdapter = TransportAdapter.Create(transportAdapterConfig);

            await transportAdapter.Start().ConfigureAwait(false);
        }
Exemplo n.º 12
0
        static async Task AsyncMain()
        {
            Console.Title = adapterName;

            var config = new TransportAdapterConfig <LearningTransport, MsmqTransport>(adapterName);

            config.CustomizeServiceControlTransport(
                customization: transport =>
            {
                //HACK: Latest MSMQ requires this setting. To be moved to the transport adapter core.
                transport.GetSettings().Set("errorQueue", "poison");
            });

            var adapter = TransportAdapter.Create(config);
            await adapter.Start().ConfigureAwait(false);

            Console.WriteLine();
            Console.WriteLine($"{adapterName} created and configured; press any key to stop program.");
            Console.WriteLine();
            Console.ReadKey();

            await adapter.Stop().ConfigureAwait(false);
        }
Exemplo n.º 13
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.ASBAdapter.Adapter";
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <AzureServiceBusTransport, AzureServiceBusTransport>("ServiceControl.ASB.Adapter");

        #endregion

#pragma warning disable 618

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            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.");
            }
            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.UseNamespaceAliasesInsteadOfConnectionStrings();
            var namespacePartitioning = transport.NamespacePartitioning();
            namespacePartitioning.AddNamespace("sales", salesConnectionString);
            namespacePartitioning.AddNamespace("shipping", shippingConnectionString);
            namespacePartitioning.UseStrategy <RoundRobinNamespacePartitioning>();
            transport.UseForwardingTopology();
            var composition = transport.Composition();
            composition.UseStrategy <HierarchyComposition>()
            .PathGenerator(path => "scadapter/");

            WorkaroundForServializerRequiredByASB(transport);
        });

        #endregion

#pragma warning restore 618

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString.SC");
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception("Could not read 'AzureServiceBus.ConnectionString.SC' environment variable. Check sample prerequisites.");
            }
            transport.ConnectionString(connectionString);
            transport.UseEndpointOrientedTopology();

            WorkaroundForServializerRequiredByASB(transport);
        });

        #endregion

        #region UseNamespaceHeader

        transportAdapterConfig.RedirectRetriedMessages((failedQ, headers) =>
        {
            if (headers.TryGetValue(AdapterSpecificHeaders.OriginalNamespace, out var namespaceAlias))
            {
                return($"{failedQ}@{namespaceAlias}");
            }
            return(failedQ);
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.ASB";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 14
0
    static async Task Main()
    {
        Console.Title = "Samples.ServiceControl.ASQAdapter.Adapter";

        #region AdapterTransport

        var transportAdapterConfig =
            new TransportAdapterConfig <AzureStorageQueueTransport, AzureStorageQueueTransport>("ServiceControl.ASQ.Adapter");

        #endregion

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            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);

            #region serializer-workaround

            var settings = transport.GetSettings();

            // Register serializer used to serialize MessageWrapper (custom MessageWrapper serializer or endpoint's serializer different than JSON)
            var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder());
            settings.Set("MainSerializer", serializer);

            #endregion
        });

        #endregion

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            var connectionString = Environment.GetEnvironmentVariable("AzureStorageQueue.ConnectionString.SC");
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception("Could not read 'AzureStorageQueue.ConnectionString.SC' environment variable. Check sample prerequisites.");
            }

            transport.ConnectionString(connectionString);

            #region serializer-workaround

            var settings = transport.GetSettings();

            // Register serializer used to serialize MessageWrapper (custom MessageWrapper serializer or endpoint's serializer different than JSON)
            var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder());
            settings.Set("MainSerializer", serializer);

            #endregion
        });

        #endregion

        #region UseStorageAccountHeader

        transportAdapterConfig.RedirectRetriedMessages((failedQ, headers) =>
        {
            if (headers.TryGetValue(AdapterSpecificHeaders.OriginalStorageAccountAlias, out var storageAccountAlias))
            {
                return($"{failedQ}@{storageAccountAlias}");
            }
            return(failedQ);
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.ASQ";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }
Exemplo n.º 15
0
    static async Task AsyncMain()
    {
        #region AdapterTransport

        var transportAdapterConfig = new TransportAdapterConfig <SqlServerTransport, SqlServerTransport>("ServiceControl.SqlServer.Adapter");

        #endregion

        #region EndpointSideConfig

        transportAdapterConfig.CustomizeEndpointTransport(
            customization: transport =>
        {
            transport.ConnectionString(
                @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True;Max Pool Size=100;Min Pool Size=10");

            //Use custom schema
            transport.DefaultSchema("adapter");

            //Necassary to correctly route retried messages because
            //SQL Server transport 2.x did not include schema information in the address
            transport.UseSchemaForQueue("Samples.ServiceControl.SqlServerTransportAdapter.Shipping", "shipping");

            //HACK: SQLServer expects this to be present. Will be solved in SQL 3.1
            transport.GetSettings().Set <EndpointInstances>(new EndpointInstances());
        });

        #endregion

        #region SCSideConfig

        transportAdapterConfig.CustomizeServiceControlTransport(
            customization: transport =>
        {
            transport.ConnectionString(
                @"Data Source=.\SQLEXPRESS;Initial Catalog=ServiceControl;Integrated Security=True;Max Pool Size=100;Min Pool Size=10");

            //HACK: SQLServer expects this to be present. Will be solved in SQL 3.1
            var settings = transport.GetSettings();
            settings.Set <EndpointInstances>(new EndpointInstances());
        });

        #endregion

        #region ControlQueueOverride

        transportAdapterConfig.ServiceControlSideControlQueue = "Particular.ServiceControl.SQL";

        #endregion

        var adapter = TransportAdapter.Create(transportAdapterConfig);

        await adapter.Start()
        .ConfigureAwait(false);

        Console.WriteLine("Press <enter> to shutdown adapter.");
        Console.ReadLine();

        await adapter.Stop()
        .ConfigureAwait(false);
    }