예제 #1
0
        static void Configure(StandardConfigurer <ITransport> configurer, Func <IRebusLoggerFactory, OracleConnectionHelper> connectionProviderFactory, string tableName, string inputQueueName)
        {
            configurer.Register(context =>
            {
                var rebusLoggerFactory = context.Get <IRebusLoggerFactory>();
                var asyncTaskFactory   = context.Get <IAsyncTaskFactory>();
                var rebusTime          = context.Get <IRebusTime>();
                var connectionProvider = connectionProviderFactory(rebusLoggerFactory);
                var transport          = new OracleTransport(connectionProvider, tableName, inputQueueName, rebusLoggerFactory, asyncTaskFactory, rebusTime);
                transport.EnsureTableIsCreated();
                return(transport);
            });

            configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager());

            configurer.OtherService <IPipeline>().Decorate(c =>
            {
                var pipeline = c.Get <IPipeline>();

                return(new PipelineStepRemover(pipeline)
                       .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)));
            });
        }
        static void ConfigureOneWayClient(StandardConfigurer <ITransport> configurer, AmazonSQSTransportOptions options)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var asyncTaskFactory   = c.Get <IAsyncTaskFactory>();

                return(new AmazonSqsTransport(null, rebusLoggerFactory, asyncTaskFactory, options));
            });

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);

            if (options.UseNativeDeferredMessages)
            {
                configurer
                .OtherService <IPipeline>()
                .Decorate(p =>
                {
                    var pipeline = p.Get <IPipeline>();

                    return(new PipelineStepRemover(pipeline)
                           .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)));
                });

                configurer.OtherService <ITimeoutManager>()
                .Register(c => new DisabledTimeoutManager(), description: SqsTimeoutManagerText);
            }
        }
예제 #3
0
        /// <summary>
        /// Configures Rebus to use Azure Service Bus to transport messages as a one-way client (i.e. will not be able to receive any messages)
        /// </summary>
        public static AzureServiceBusTransportClientSettings UseAzureServiceBusAsOneWayClient(this StandardConfigurer <ITransport> configurer, string connectionString, ITokenProvider tokenProvider = null)
        {
            var settingsBuilder = new AzureServiceBusTransportClientSettings();

            configurer.OtherService <Options>().Decorate(c =>
            {
                var options = c.Get <Options>();
                options.ExternalTimeoutManagerAddressOrNull = AzureServiceBusTransport.MagicDeferredMessagesAddress;
                return(options);
            });

            configurer
            .OtherService <AzureServiceBusTransport>()
            .Register(c =>
            {
                var cancellationToken  = c.Get <CancellationToken>();
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var asyncTaskFactory   = c.Get <IAsyncTaskFactory>();
                var nameFormatter      = c.Get <INameFormatter>();

                return(new AzureServiceBusTransport(
                           connectionString: connectionString,
                           queueName: null,
                           rebusLoggerFactory: rebusLoggerFactory,
                           asyncTaskFactory: asyncTaskFactory,
                           nameFormatter: nameFormatter,
                           cancellationToken: cancellationToken,
                           tokenProvider: tokenProvider
                           ));
            });

            RegisterServices(configurer, () => settingsBuilder.LegacyNamingEnabled);

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);

            return(settingsBuilder);
        }
        public static EtcdConfigurationBuilder UseEtcd(this StandardConfigurer <IRouter> configurer, string url)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            var typeHelper           = new TypeHelper();
            var configurationBuilder = new EtcdConfigurationBuilder(typeHelper);

            configurer.OtherService <EtcdClient>().Register(c =>
            {
                var etcdClient = new EtcdClient(url);
                var transport  = c.Get <ITransport>();

                configurationBuilder.Initialize(etcdClient, transport);

                return(etcdClient);
            });

            configurer.OtherService <EtcdRouter>().Register(c =>
            {
                var etcdClient = c.Get <EtcdClient>();

                return(new EtcdRouter(etcdClient, typeHelper));
            });

            configurer.Register(c => c.Get <EtcdRouter>());

            configurer.OtherService <ISubscriptionStorage>().Register(c => c.Get <EtcdRouter>());

            return(configurationBuilder);
        }
예제 #5
0
        static void Configure(StandardConfigurer <ITransport> configurer, Func <IRebusLoggerFactory, IDbConnectionProvider> connectionProviderFactory, string inputQueueName, TransportFactoryDelegate transportFactory)
        {
            configurer.Register(context =>
            {
                var rebusLoggerFactory = context.Get <IRebusLoggerFactory>();
                var connectionProvider = connectionProviderFactory(rebusLoggerFactory);
                var transport          = transportFactory(context, connectionProvider, inputQueueName);
                if (inputQueueName != null)
                {
                    transport.EnsureTableIsCreated();
                }
                return(transport);
            });

            configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager());

            configurer.OtherService <IPipeline>().Decorate(c =>
            {
                var pipeline = c.Get <IPipeline>();

                return(new PipelineStepRemover(pipeline)
                       .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)));
            });

            configurer.OtherService <Options>().Decorate(c =>
            {
                var options = c.Get <Options>();

                if (string.IsNullOrWhiteSpace(options.ExternalTimeoutManagerAddressOrNull))
                {
                    options.ExternalTimeoutManagerAddressOrNull = SqlServerTransport.MagicExternalTimeoutManagerAddress;
                }

                return(options);
            });
        }
예제 #6
0
 public static void UseActiveMq(this StandardConfigurer <ITransport> configurer, Action <IActiveMqTransportSettings> activeMqTransportSettingsFunc)
 {
     configurer
     .OtherService <IActiveMqTransportSettings>()
     .Register(c =>
     {
         IActiveMqTransportSettings settings = new ActiveMqTransportSettings();
         activeMqTransportSettingsFunc(settings);
         return(settings);
     });
     configurer
     .Register(context =>
     {
         var settings = context.Get <IActiveMqTransportSettings>();
         return(new ActiveMqTransport(settings));
     });
 }
예제 #7
0
        /// <summary>
        /// Uses the given <see cref="StandardConfigurer{TService}"/> of <see cref="ITransport"/> to set the number of workers
        /// to zero (effectively disabling message processing) and installs a decorator of <see cref="IBus"/> that prevents
        /// further modification of the number of workers (thus preventing accidentally starting workers when there's no input queue).
        /// </summary>
        public static void ConfigureOneWayClient(StandardConfigurer <ITransport> configurer)
        {
            configurer.Options.NumberOfWorkers = 0;

            configurer.OtherService <IBus>().Decorate(c =>
            {
                var transport = c.Get <ITransport>();

                if (transport.Address != null)
                {
                    throw new InvalidOperationException($"Cannot configure this bus to be a one-way client, because the transport is configured with '{transport.Address}' as its input queue. One-way clients must have a NULL input queue, otherwise the transport could be fooled into believing it was supposed to receive messages");
                }

                var options             = c.Get <Options>();
                options.NumberOfWorkers = 0;

                var realBus            = c.Get <IBus>();
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var busDecorator       = new OneWayClientBusDecorator(realBus, rebusLoggerFactory);

                return(busDecorator);
            }, description: OneWayDecoratorDescription);
        }
 /// <summary>
 /// Extends Rebus' built-in deadlettering with the ability to use Azure Service Bus' built-in deadlettering
 /// </summary>
 public static void UseNativeDeadlettering(this StandardConfigurer <ITransport> configurer)
 {
     configurer
     .OtherService <IErrorHandler>()
     .Decorate(c => new BuiltInDeadletteringErrorHandler(c.Get <IErrorHandler>()));
 }
예제 #9
0
        /// <summary>
        /// Configures Rebus to use Azure Service Bus queues to transport messages, connecting to the service bus instance pointed to by the connection string
        /// (or the connection string with the specified name from the current app.config)
        /// </summary>
        public static AzureServiceBusTransportSettings UseAzureServiceBus(this StandardConfigurer <ITransport> configurer, string connectionStringNameOrConnectionString, string inputQueueAddress, AzureServiceBusMode mode = AzureServiceBusMode.Standard)
        {
            var connectionString = GetConnectionString(connectionStringNameOrConnectionString);
            var settingsBuilder  = new AzureServiceBusTransportSettings();

            if (mode == AzureServiceBusMode.Basic)
            {
                configurer.Register(c =>
                {
                    var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                    var transport          = new BasicAzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory);

                    if (settingsBuilder.PrefetchingEnabled)
                    {
                        transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch);
                    }

                    transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled;

                    transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled;

                    return(transport);
                });

                return(settingsBuilder);
            }

            configurer
            .OtherService <AzureServiceBusTransport>()
            .Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var transport          = new AzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory);

                if (settingsBuilder.PrefetchingEnabled)
                {
                    transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch);
                }

                transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled;

                transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled;

                return(transport);
            });

            configurer
            .OtherService <ISubscriptionStorage>()
            .Register(c => c.Get <AzureServiceBusTransport>(), description: AsbSubStorageText);

            configurer.Register(c => c.Get <AzureServiceBusTransport>());

            configurer.OtherService <IPipeline>().Decorate(c =>
            {
                var pipeline = c.Get <IPipeline>();

                return(new PipelineStepRemover(pipeline)
                       .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)));
            });

            configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsbTimeoutManagerText);

            return(settingsBuilder);
        }