public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
        {
            QueuePeekerOptions peekerOptions;

            if (!settings.TryGet(out peekerOptions))
            {
                peekerOptions = new QueuePeekerOptions();
            }

            var connectionFactory = CreateLegacyConnectionFactory();

            var queuePurger = new LegacyQueuePurger(connectionFactory);
            var queuePeeker = new LegacyQueuePeeker(connectionFactory, peekerOptions);

            var expiredMessagesPurger = CreateExpiredMessagesPurger(connectionFactory);
            var schemaVerification    = new SchemaInspector(queue => connectionFactory.OpenNewConnection(queue.Name));

            SqlScopeOptions scopeOptions;

            if (!settings.TryGet(out scopeOptions))
            {
                scopeOptions = new SqlScopeOptions();
            }

            TimeSpan waitTimeCircuitBreaker;

            if (!settings.TryGet(SettingsKeys.TimeToWaitBeforeTriggering, out waitTimeCircuitBreaker))
            {
                waitTimeCircuitBreaker = TimeSpan.FromSeconds(30);
            }

            Func <TransportTransactionMode, ReceiveStrategy> receiveStrategyFactory =
                guarantee =>
            {
                if (guarantee != TransportTransactionMode.TransactionScope)
                {
                    throw new Exception("Legacy multiinstance mode is supported only with TransportTransactionMode=TransactionScope");
                }

                return(new LegacyProcessWithTransactionScope(scopeOptions.TransactionOptions, connectionFactory, new FailureInfoStorage(1000)));
            };

            Func <string, TableBasedQueue> queueFactory = x => new TableBasedQueue(addressTranslator.Parse(x).QualifiedTableName, x);

            return(new TransportReceiveInfrastructure(
                       () => new MessagePump(receiveStrategyFactory, queueFactory, queuePurger, expiredMessagesPurger, queuePeeker, schemaVerification, waitTimeCircuitBreaker),
                       () => new LegacyQueueCreator(connectionFactory, addressTranslator),
                       () => Task.FromResult(StartupCheckResult.Success)));
        }
Beispiel #2
0
        public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
        {
            if (!settings.TryGet(out SqlScopeOptions scopeOptions))
            {
                scopeOptions = new SqlScopeOptions();
            }

            settings.TryGet(out TransportTransactionMode transactionMode);
            diagnostics.Add("NServiceBus.Transport.SqlServer.Transactions", new
            {
                TransactionMode = transactionMode,
                scopeOptions.TransactionOptions.IsolationLevel,
                scopeOptions.TransactionOptions.Timeout
            });

            if (!settings.TryGet(SettingsKeys.TimeToWaitBeforeTriggering, out TimeSpan waitTimeCircuitBreaker))
            {
                waitTimeCircuitBreaker = TimeSpan.FromSeconds(30);
            }
            diagnostics.Add("NServiceBus.Transport.SqlServer.CircuitBreaker", new
            {
                TimeToWaitBeforeTriggering = waitTimeCircuitBreaker
            });

            if (!settings.TryGet(out QueuePeekerOptions queuePeekerOptions))
            {
                queuePeekerOptions = new QueuePeekerOptions();
            }

            var createMessageBodyComputedColumn = settings.GetOrDefault <bool>(SettingsKeys.CreateMessageBodyComputedColumn);

            var connectionFactory = CreateConnectionFactory();

            Func <TransportTransactionMode, ReceiveStrategy> receiveStrategyFactory =
                guarantee => SelectReceiveStrategy(guarantee, scopeOptions.TransactionOptions, connectionFactory);

            var queuePurger = new QueuePurger(connectionFactory);
            var queuePeeker = new QueuePeeker(connectionFactory, queuePeekerOptions);

            var expiredMessagesPurger = CreateExpiredMessagesPurger(connectionFactory);
            var schemaVerification    = new SchemaInspector(queue => connectionFactory.OpenNewConnection());

            Func <string, TableBasedQueue> queueFactory = queueName => new TableBasedQueue(addressTranslator.Parse(queueName).QualifiedTableName, queueName);

            var delayedMessageStore = GetDelayedQueueTableName();

            var sendInfra = ConfigureSendInfrastructure();

            return(new TransportReceiveInfrastructure(
                       () =>
            {
                var pump = new MessagePump(receiveStrategyFactory, queueFactory, queuePurger, expiredMessagesPurger, queuePeeker, schemaVerification, waitTimeCircuitBreaker);
                if (delayedDeliverySettings == null)
                {
                    return pump;
                }
                var dispatcher = sendInfra.DispatcherFactory();
                var delayedMessageProcessor = new DelayedMessageProcessor(dispatcher);
                return new DelayedDeliveryMessagePump(pump, delayedMessageProcessor);
            },
                       () =>
            {
                var creator = new QueueCreator(connectionFactory, addressTranslator, createMessageBodyComputedColumn);
                if (delayedDeliverySettings == null)
                {
                    return creator;
                }
                return new DelayedDeliveryQueueCreator(connectionFactory, creator, delayedMessageStore, createMessageBodyComputedColumn);
            },
                       () => CheckForAmbientTransactionEnlistmentSupport(connectionFactory, scopeOptions.TransactionOptions)));
        }
 public MessagePump(Func <TransportTransactionMode, ReceiveStrategy> receiveStrategyFactory, Func <string, TableBasedQueue> queueFactory, IPurgeQueues queuePurger, ExpiredMessagesPurger expiredMessagesPurger, IPeekMessagesInQueue queuePeeker, SchemaInspector schemaInspector, TimeSpan waitTimeCircuitBreaker)
 {
     this.receiveStrategyFactory = receiveStrategyFactory;
     this.queuePurger            = queuePurger;
     this.queueFactory           = queueFactory;
     this.expiredMessagesPurger  = expiredMessagesPurger;
     this.queuePeeker            = queuePeeker;
     this.schemaInspector        = schemaInspector;
     this.waitTimeCircuitBreaker = waitTimeCircuitBreaker;
 }
Beispiel #4
0
        public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
        {
            if (!settings.TryGet(out SqlScopeOptions scopeOptions))
            {
                scopeOptions = new SqlScopeOptions();
            }

            settings.TryGet(out TransportTransactionMode transactionMode);
            diagnostics.Add("NServiceBus.Transport.SqlServer.Transactions", new
            {
                TransactionMode = transactionMode,
                scopeOptions.TransactionOptions.IsolationLevel,
                scopeOptions.TransactionOptions.Timeout
            });

            if (!settings.TryGet(SettingsKeys.TimeToWaitBeforeTriggering, out TimeSpan waitTimeCircuitBreaker))
            {
                waitTimeCircuitBreaker = TimeSpan.FromSeconds(30);
            }
            diagnostics.Add("NServiceBus.Transport.SqlServer.CircuitBreaker", new
            {
                TimeToWaitBeforeTriggering = waitTimeCircuitBreaker
            });

            if (!settings.TryGet(out QueuePeekerOptions queuePeekerOptions))
            {
                queuePeekerOptions = new QueuePeekerOptions();
            }

            var createMessageBodyComputedColumn = settings.GetOrDefault <bool>(SettingsKeys.CreateMessageBodyComputedColumn);

            Func <TransportTransactionMode, ReceiveStrategy> receiveStrategyFactory =
                guarantee => SelectReceiveStrategy(guarantee, scopeOptions.TransactionOptions, connectionFactory);

            var queuePurger = new QueuePurger(connectionFactory);
            var queuePeeker = new QueuePeeker(connectionFactory, queuePeekerOptions);

            var expiredMessagesPurger = CreateExpiredMessagesPurger();
            var schemaVerification    = new SchemaInspector(queue => connectionFactory.OpenNewConnection());

            Func <string, TableBasedQueue> queueFactory = queueName => new TableBasedQueue(addressTranslator.Parse(queueName).QualifiedTableName, queueName);

            //Create delayed delivery infrastructure
            CanonicalQueueAddress delayedQueueCanonicalAddress = null;

            if (false == settings.GetOrDefault <bool>(SettingsKeys.DisableDelayedDelivery))
            {
                var delayedDeliverySettings = settings.GetOrDefault <DelayedDeliverySettings>();
                settings.AddStartupDiagnosticsSection("NServiceBus.Transport.SqlServer.DelayedDelivery", new
                {
                    Native = true,
                    delayedDeliverySettings.Suffix,
                    delayedDeliverySettings.Interval,
                    BatchSize     = delayedDeliverySettings.MatureBatchSize,
                    TimoutManager = delayedDeliverySettings.EnableMigrationMode ? "enabled" : "disabled"
                });

                delayedQueueCanonicalAddress = GetDelayedTableAddress(delayedDeliverySettings);
                var inputQueueTable     = addressTranslator.Parse(ToTransportAddress(logicalAddress())).QualifiedTableName;
                var delayedMessageTable = new DelayedMessageTable(delayedQueueCanonicalAddress.QualifiedTableName, inputQueueTable);

                //Allows dispatcher to store messages in the delayed store
                delayedMessageStore        = delayedMessageTable;
                dueDelayedMessageProcessor = new DueDelayedMessageProcessor(delayedMessageTable, connectionFactory, delayedDeliverySettings.Interval, delayedDeliverySettings.MatureBatchSize);
            }

            return(new TransportReceiveInfrastructure(
                       () => new MessagePump(receiveStrategyFactory, queueFactory, queuePurger, expiredMessagesPurger, queuePeeker, schemaVerification, waitTimeCircuitBreaker),
                       () => new QueueCreator(connectionFactory, addressTranslator, delayedQueueCanonicalAddress, createMessageBodyComputedColumn),
                       () => CheckForAmbientTransactionEnlistmentSupport(scopeOptions.TransactionOptions)));
        }
        public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
        {
            SqlScopeOptions scopeOptions;

            if (!settings.TryGet(out scopeOptions))
            {
                scopeOptions = new SqlScopeOptions();
            }

            TimeSpan waitTimeCircuitBreaker;

            if (!settings.TryGet(SettingsKeys.TimeToWaitBeforeTriggering, out waitTimeCircuitBreaker))
            {
                waitTimeCircuitBreaker = TimeSpan.FromSeconds(30);
            }

            QueuePeekerOptions queuePeekerOptions;

            if (!settings.TryGet(out queuePeekerOptions))
            {
                queuePeekerOptions = new QueuePeekerOptions();
            }

            var connectionFactory = CreateConnectionFactory();

            Func <TransportTransactionMode, ReceiveStrategy> receiveStrategyFactory =
                guarantee => SelectReceiveStrategy(guarantee, scopeOptions.TransactionOptions, connectionFactory);

            var queuePurger = new QueuePurger(connectionFactory);
            var queuePeeker = new QueuePeeker(connectionFactory, queuePeekerOptions);

            var expiredMessagesPurger = CreateExpiredMessagesPurger(connectionFactory);
            var schemaVerification    = new SchemaInspector(queue => connectionFactory.OpenNewConnection());

            Func <string, TableBasedQueue> queueFactory = queueName => new TableBasedQueue(addressTranslator.Parse(queueName).QualifiedTableName, queueName);

            var delayedMessageStore = GetDelayedQueueTableName();

            var sendInfra = ConfigureSendInfrastructure();

            return(new TransportReceiveInfrastructure(
                       () =>
            {
                var pump = new MessagePump(receiveStrategyFactory, queueFactory, queuePurger, expiredMessagesPurger, queuePeeker, schemaVerification, waitTimeCircuitBreaker);
                if (delayedDeliverySettings == null)
                {
                    return pump;
                }
                var dispatcher = sendInfra.DispatcherFactory();
                var delayedMessageProcessor = new DelayedMessageProcessor(dispatcher, settings.LocalAddress());
                return new DelayedDeliveryMessagePump(pump, delayedMessageProcessor);
            },
                       () =>
            {
                var creator = new QueueCreator(connectionFactory, addressTranslator);
                if (delayedDeliverySettings == null)
                {
                    return creator;
                }
                return new DelayedDeliveryQueueCreator(connectionFactory, creator, delayedMessageStore);
            },
                       () => Task.FromResult(StartupCheckResult.Success)));
        }