public DelayedDeliveryMessagePump(IPushMessages pump, DelayedMessageProcessor delayedMessageProcessor)
 {
     this.pump = pump;
     this.delayedMessageProcessor = delayedMessageProcessor;
 }
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 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)));
        }