static void ConfigureConnection(TransportExtensions <SqlServerTransport> transport, TransportSettings transportSettings)
        {
            var connectionString = transportSettings.ConnectionString
                                   .RemoveCustomConnectionStringParts(out var customSchema, out var subscriptionsTableSetting);

            var subscriptions = transport.SubscriptionSettings();

            if (customSchema != null)
            {
                transport.DefaultSchema(customSchema);
                subscriptions.SubscriptionTableName(defaultSubscriptionTableName, customSchema);
            }

            if (subscriptionsTableSetting != null)
            {
                var subscriptionsAddress = QueueAddress.Parse(subscriptionsTableSetting);

                subscriptions.SubscriptionTableName(
                    tableName: subscriptionsAddress.Table,
                    schemaName: subscriptionsAddress.Schema ?? customSchema,
                    catalogName: subscriptionsAddress.Catalog
                    );
            }

            transport.ConnectionString(connectionString);

            transport.EnableMessageDrivenPubSubCompatibilityMode();
        }
Пример #2
0
        protected override async Task ExecuteAsync(CancellationToken token)
        {
            const string EndpointName          = "endpoint name";
            var          endpointConfiguration = new EndpointConfiguration(EndpointName);

            endpointConfiguration.UniquelyIdentifyRunningInstance().UsingNames(EndpointName, Environment.MachineName);


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

            endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions
            .DefiningEventsAs(_ => _.Name.EndsWith("Event"))
            .DefiningCommandsAs(_ => _.Name.EndsWith("Command"))
            .DefiningMessagesAs(_ => _.Name.EndsWith("Message"));

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

            NServiceBus.Transport.SQLServer.SubscriptionSettings
                subscriptionSettings = transport.SubscriptionSettings();
            subscriptionSettings.DisableSubscriptionCache();
            subscriptionSettings.SubscriptionTableName("subscriptions", "transportSchema");

            transport.Routing().RouteToEndpoint(
                Assembly.GetAssembly(typeof(MyCommand)),
                EndpointName);


            DelayedDeliverySettings delayedDeliverySettings = transport.NativeDelayedDelivery();

            delayedDeliverySettings.DisableTimeoutManagerCompatibility();

            transport
            .Transactions(TransportTransactionMode.ReceiveOnly)
            .ConnectionString("Data Source=sqlserver;Initial Catalog=transport;User ID=worker;Password=password;Max Pool Size=100;")
            .TransactionScopeOptions(TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted)
            .DefaultSchema("transportSchema");

            this.endpoint = await Endpoint.Start(endpointConfiguration);

            while (!token.IsCancellationRequested)
            {
                await Task.Delay(1000, token);
            }
        }