public void ActivateHandlersWith(IHandlerActivator activator)
 {
     if (activator != null)
     {
         _transport.HandlerActivator = activator;
     }
 }
예제 #2
0
        public InternalHandlersContributor(IHandlerActivator innerHandlerActivator, ISubscriptionStorage subscriptionStorage)
        {
            _innerHandlerActivator = innerHandlerActivator;

            _internalHandlers = new Dictionary <Type, IHandleMessages[]>
            {
                { typeof(SubscribeRequest), new IHandleMessages[] { new SubscribeRequestHandler(subscriptionStorage) } },
                { typeof(UnsubscribeRequest), new IHandleMessages[] { new UnsubscribeRequestHandler(subscriptionStorage) } }
            };
        }
예제 #3
0
        private RebusConfigurer ConfigureRebus(IHandlerActivator activator)
        {
            RebusConfigurer rebusConfigurer = Config.Configure
                                              .With(activator)
            ;

            _configureActions.ForEach(ca => ca(rebusConfigurer));

            return(rebusConfigurer);
        }
예제 #4
0
        internal RebusConfigurer(IHandlerActivator handlerActivator)
        {
            if (handlerActivator == null) throw new ArgumentNullException(nameof(handlerActivator));

            _injectionist.Register(c => handlerActivator);

            if (handlerActivator is IContainerAdapter)
            {
                _injectionist.Register(c => (IContainerAdapter)handlerActivator);
            }
        }
예제 #5
0
파일: OneWay.cs 프로젝트: mindisk/Rebus
    private static async Task <IBus> Subscriber(IHandlerActivator activator, InMemNetwork network, InMemorySubscriberStore subscriberStore)
    {
        var subscriber = Configure.With(activator)
                         .Transport(t => t.UseInMemoryTransport(network, "subscriber"))
                         .Subscriptions(s => s.StoreInMemory(subscriberStore))
                         .Start();

        await subscriber.Subscribe <Message>();

        return(subscriber);
    }
예제 #6
0
 public NotifyUserOnDeactivationHandler(ServiceBusConfiguration serviceBusConfiguration, IHandlerActivator activator)
 {
     _serviceBusConfiguration = serviceBusConfiguration;
     if (string.IsNullOrEmpty(serviceBusConfiguration?.Api))
     {
         throw new ArgumentNullException(nameof(ServiceBusConfiguration.Api));
     }
     if (string.IsNullOrEmpty(serviceBusConfiguration?.TrackerApi))
     {
         throw new ArgumentNullException(nameof(ServiceBusConfiguration.TrackerApi));
     }
     _activator = activator;
 }
예제 #7
0
        static void ConfigureSerilog(IHandlerActivator activator)
        {
            // configure Serilog
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole()
                         .MinimumLevel.Verbose()
                         .CreateLogger();

            // configure Rebus
            Configure.With(activator)
            .Logging(l => l.Serilog())
            .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "logging"))
            .Start();
        }
 public EventHubServiceBuilder(
     IHandlerActivator handlerActivator,
     IEventHubSettings settings,
     ILogger logger,
     IExceptionLogger exceptionLogger,
     IHubEventErrorBus hubEventErrorBus,
     IHubCommandErrorBus hubCommandErrorBus)
 {
     _handlerActivator   = handlerActivator;
     _settings           = settings;
     _logger             = logger;
     _exceptionLogger    = exceptionLogger;
     _hubEventErrorBus   = hubEventErrorBus;
     _hubCommandErrorBus = hubCommandErrorBus;
 }
예제 #9
0
 protected IBus CreateBus(IHandlerActivator activator, Action <OptionsConfigurer> optionsConfigurer, InMemNetwork inMemNetwork = null)
 {
     return(Configure
            .With(activator)
            .Logging(l => l.Use(_loggerFactory ?? (IRebusLoggerFactory) new NullLoggerFactory()))
            .Options(o =>
     {
         o.SimpleRetryStrategy(ErrorQueueName, 1);
         //o.LogPipeline(true);
         optionsConfigurer?.Invoke(o);
     })
            .Transport(t => t.UseInMemoryTransport(inMemNetwork ?? new InMemNetwork(), InputQueueName))
            .Routing(r => r.TypeBased().MapAssemblyOf <TestMessage>(InputQueueName))
            .Start());
 }
예제 #10
0
        /// <summary>
        ///     Registers the specified <see cref="IHandlerActivator"/> for the Rebus bus
        /// </summary>
        public static HostConfigurator UsingRebusHandlerActivator(this HostConfigurator configurator, IHandlerActivator handlerActivator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (handlerActivator == null)
            {
                throw new ArgumentNullException(nameof(handlerActivator));
            }

            CustomHandlerActivator = handlerActivator;

            return(configurator);
        }
예제 #11
0
 static IBus ConfigureBus <T>(IHandlerActivator activator, InMemNetwork network, string queue)
 {
     return(Configure.With(activator)
            .Logging(l => l.ColoredConsole(minLevel: UsedLogLevel))
            .Transport(t => t.UseInMemoryTransport(network, queue))
            .Options(o =>
     {
         o.SetMaxParallelism(1); o.SetNumberOfWorkers(1);
     })
            //.Subscriptions(s => s.UseJsonFile("subs.json"))
            //.Sagas(s => s.UseFilesystem("processes"))
            .Routing(r => r.TypeBased()
                     .Map <T>(queue))
            .Start());
 }
예제 #12
0
        static void ConfigureNLog(IHandlerActivator activator)
        {
            // configure NLog
            var configuration = new LoggingConfiguration
            {
                LoggingRules = { new LoggingRule("*", LogLevel.Debug, new ConsoleTarget("console")) }
            };

            LogManager.Configuration = configuration;

            // configure Rebus
            Configure.With(activator)
            .Logging(l => l.NLog())
            .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "logging"))
            .Start();
        }
예제 #13
0
 public EventHubService(IHandlerActivator handlerActivator,
                        IExceptionLogger exceptionLogger,
                        IEventHubSettings settings,
                        IHubEventErrorBus hubEventErrorBus,
                        IHubCommandErrorBus hubCommandErrorBus,
                        ILogger logger)
 {
     _handlerActivator   = handlerActivator;
     _exceptionLogger    = exceptionLogger;
     _settings           = settings;
     _hubEventErrorBus   = hubEventErrorBus;
     _hubCommandErrorBus = hubCommandErrorBus;
     _logger             = logger;
     foreach (var connection in _settings.AzureEventHubConnectionStrings)
     {
         _connectionStrings.Add(connection.Namespace, connection.ConnectionString);
     }
 }
예제 #14
0
 private static IBus ConfigureWithRabbitMqTransport(
     IHandlerActivator handler,
     RabbitMqConfig rabbitMqConfig,
     string inputQueue)
 {
     return(Configure.With(handler)
            .Options(optionsConfigure =>
     {
         // Add standard header converter extension.
         // The extension will convert incoming messages with standard headers to rebus headers,
         // and convert rebus headers to standard headers on outgoing messages.
         optionsConfigure.AddStandardHeaderConverter();
     })
            .Transport(t =>
                       t.UseRabbitMq(rabbitMqConfig.ConnectionString, inputQueue)
                       .EnablePublisherConfirms())
            .Start());
 }
 public EventHubProcessor(IEventHubSettings settings,
                          IHandlerActivator handlerActivator,
                          IExceptionLogger exceptionLogger,
                          IHubEventErrorBus hubEventErrorBus,
                          IHubCommandErrorBus hubCommandErrorBus,
                          IDictionary <Type, Type> commandHandlers,
                          IDictionary <Type, ISet <Type> > eventHandlers,
                          ILogger logger)
 {
     _settings           = settings;
     _handlerActivator   = handlerActivator;
     _exceptionLogger    = exceptionLogger;
     _hubEventErrorBus   = hubEventErrorBus;
     _hubCommandErrorBus = hubCommandErrorBus;
     _commandHandlers    = commandHandlers;
     _eventHandlers      = eventHandlers;
     _logger             = logger;
 }
예제 #16
0
 static IBus ConfigureBus <T>(IHandlerActivator activator, string queue, int prefetch, int workers, int parallelism)
 {
     return(Configure.With(activator)
            .Logging(l => l.ColoredConsole(minLevel: UsedLogLevel))
            .Transport(t => t.UseRabbitMq(RabbitMqConnectionString, queue).Prefetch(prefetch).ClientConnectionName(string.Format("Consumer Connection {0}", queue)))
            .Options(o =>
     {
         o.SetMaxParallelism(parallelism); o.SetNumberOfWorkers(workers);
         o.Decorate <IPipeline>(res =>
         {
             var pipeline = res.Get <IPipeline>();
             var injector = new PipelineStepInjector(pipeline).OnReceive(new CustomIncomingMetricStep(stats, queue), PipelineRelativePosition.After, typeof(DeserializeIncomingMessageStep));
             return injector;
         });
     })
            //.Sagas(s => s.UseFilesystem("processes"))
            .Routing(r => r.TypeBased()
                     .Map <T>(queue))
            .Start());
 }
예제 #17
0
파일: Configure.cs 프로젝트: zlepper/Rebus
        /// <summary>
        /// Call this method with the chosen implementation of <see cref="IHandlerActivator"/> (e.g. <see cref="BuiltinHandlerActivator"/>, or one
        /// that is backed by your favorite IoC container) in order to start configuring a
        /// Rebus instance
        /// </summary>
        public static RebusConfigurer With(IHandlerActivator handlerActivator)
        {
            if (handlerActivator == null)
            {
                throw new ArgumentNullException(nameof(handlerActivator), @"Please remember to pass a handler activator to the .With(..) method.

The handler activator is responsible for looking up handlers for incoming messages, which makes for a pretty good place to use an adapter for an IoC container (because then your handlers can have dependencies injected).

If you are interested in a lightweight approach that does not depend on an IoC container, you can pass an instance of BuiltinHandlerActivator which can then be used to register handlers - either inline like this:

    activator.Handle<MyMessage>(async (bus, context, message) => {
        // handle message here
    });

or by registering a factory function like this:

    activator.Register(() => new MyHandler());
");
            }

            return(new RebusConfigurer(handlerActivator));
        }
예제 #18
0
        /// <summary>
        ///     Registers a Rebus bus as Topshelf service
        /// </summary>
        public static HostConfigurator UsingRebusAsService(this HostConfigurator configurator,
                                                           IHandlerActivator handlerActivator, Action <RebusConfigurer> rebusConfigurer)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (rebusConfigurer == null)
            {
                throw new ArgumentNullException(nameof(rebusConfigurer));
            }
            if (handlerActivator == null)
            {
                throw new ArgumentNullException(nameof(handlerActivator));
            }

            return(configurator.Service <NullService>(service =>
            {
                service.Rebus(handlerActivator, rebusConfigurer);
                service.WhenStarted(x => NullService.Start());
                service.WhenStopped(x => NullService.Stop());
                service.ConstructUsing(x => new NullService());
            }));
        }
예제 #19
0
 static void ConfigureUsing(IHandlerActivator activator)
 {
     ConfigureSerilog(activator);
     //ConfigureNLog(activator);
 }
예제 #20
0
 public DefaultHandlerFactory(IDefaultHandlerRegistry registry, IHandlerActivator activator)
 {
     this.registry  = registry ?? throw new ArgumentNullException(nameof(registry));
     this.activator = activator ?? throw new ArgumentNullException(nameof(activator));
 }
예제 #21
0
 /// <summary>
 /// Constructs the step with the <see cref="IHandlerActivator"/> to use to get the handler instances
 /// </summary>
 public ActivateHandlersStep(IHandlerActivator handlerActivator)
 {
     _handlerActivator = handlerActivator ?? throw new ArgumentNullException(nameof(handlerActivator));
 }
예제 #22
0
 /// <summary>
 /// Constructs the step with the <see cref="IHandlerActivator"/> to use to get the handler instances
 /// </summary>
 public ActivateHandlersStep(IHandlerActivator handlerActivator)
 {
     _handlerActivator = handlerActivator;
 }
예제 #23
0
        private static IBus _ConfigureAndStartRebus(IHandlerActivator handlerActivator)
        {
            var rebusConfigurer = Configure.With(handlerActivator);

            var rebusInputQueue = _configuration["Rebus:InputQueueName"];
            var rebusTransport  = _configuration["Rebus:Transport"];

            switch (rebusTransport)
            {
#if NETFRAMEWORK
            case "MSMQ":
                rebusConfigurer
                .Transport(x => x.UseMsmq(rebusInputQueue))
                .Subscriptions(x => x.UseJsonFile($"{Path.GetTempPath()}\\emailmaker_msmq_subscriptions.json"))
                ;
                break;
#endif
            case "RabbitMQ":
                rebusConfigurer.Transport(x => x.UseRabbitMq(_configuration["Rebus:RabbitMQ:ConnectionString"], rebusInputQueue));
                break;

            default:
                throw new Exception($"Unknown rebus transport: {rebusTransport}");
            }

            var rebusUnitOfWorkMode = _configuration["Rebus:UnitOfWorkMode"];
            switch (rebusUnitOfWorkMode)
            {
            case "TransactionScopeUnitOfWork":
                RebusTransactionScopeUnitOfWork.Initialize(
                    unitOfWorkFactory: IoC.Resolve <IUnitOfWorkFactory>(),
                    isolationLevel: System.Transactions.IsolationLevel.ReadCommitted,
                    transactionScopeEnlistmentAction: null
                    );
                rebusConfigurer
                .Options(o =>
                {
                    o.EnableUnitOfWork(
                        RebusTransactionScopeUnitOfWork.Create,
                        RebusTransactionScopeUnitOfWork.Commit,
                        RebusTransactionScopeUnitOfWork.Rollback,
                        RebusTransactionScopeUnitOfWork.Cleanup
                        );
                })
                ;
                break;

            case "UnitOfWork":
                RebusUnitOfWork.Initialize(
                    unitOfWorkFactory: IoC.Resolve <IUnitOfWorkFactory>(),
                    isolationLevel: System.Data.IsolationLevel.ReadCommitted
                    );
                rebusConfigurer
                .Options(o =>
                {
                    o.EnableUnitOfWork(
                        RebusUnitOfWork.Create,
                        RebusUnitOfWork.Commit,
                        RebusUnitOfWork.Rollback,
                        RebusUnitOfWork.Cleanup
                        );
                })
                ; break;

            default:
                throw new Exception($"Unknown rebus unit of work mode: {rebusUnitOfWorkMode}");
            }

            var bus = rebusConfigurer.Start();
            bus.Subscribe <EmailEnqueuedToBeSentEventMessage>().Wait();
            return(bus);
        }
예제 #24
0
 public EventBus(IHandlerActivator handlerActivator)
 {
     _handlerActivator = handlerActivator;
 }
예제 #25
0
 public Base(string apiUrl, string resource, IHandlerActivator activator)
 {
     RestClient = !string.IsNullOrEmpty(apiUrl) ? new RestClient(apiUrl) : throw new ArgumentNullException(nameof(apiUrl));
     Resource   = resource;
     ServiceBus = activator as BuiltinHandlerActivator ?? throw new ArgumentNullException(nameof(activator));
 }
예제 #26
0
 static IBus ConfigureBus <T>(IHandlerActivator activator, string queue, int prefetch, int workers = 1)
 {
     return(ConfigureBus <T>(activator, queue, prefetch, workers, workers));
 }
예제 #27
0
 public Tracker(string apiUrl, IHandlerActivator activator)
     : base(apiUrl, "trackerrequest", activator)
 {
 }
예제 #28
0
 public CommandBus(IHandlerActivator handlerActivator)
 {
     _handlerActivator = handlerActivator;
 }
예제 #29
0
 public UserNotification(string apiUrl, IHandlerActivator activator)
     : base(apiUrl, "userNotification", activator)
 {
 }
예제 #30
0
 /// <summary>
 /// Call this method with the chosen implementation of <see cref="IHandlerActivator"/> (e.g. <see cref="BuiltinHandlerActivator"/>, or one 
 /// that is backed by your favorite IoC container) in order to start configuring a
 /// Rebus instance
 /// </summary>
 public static RebusConfigurer With(IHandlerActivator handlerActivator)
 {
     return new RebusConfigurer(handlerActivator);
 }
예제 #31
0
 public ServiceBusWithHandlersBuilder(IServiceBus serviceBus, IHandlerActivator handlerActivator, ILogger logger)
 {
     _serviceBus       = serviceBus;
     _handlerActivator = handlerActivator;
     _logger           = logger;
 }
예제 #32
0
        public static async Task SDKSampleOperations(ServiceBusConfiguration serviceBusConfiguration, IHandlerActivator activator)
        {
            var tracker = new Tracker(serviceBusConfiguration.TrackerApi, activator);

            // all trackers
            var trackers = await tracker.PaginateAsync();

            // create new
            var request = await tracker.CreateAsync(new CreateTrackerRequest
            {
                Type = (int)TrackerRequestType.DeleteUser
            });

            if (request != null)
            {
                // update state if required only
                var update = await tracker.UpdateStepAsync(request.Id, new UpdateTrackerStepRequest
                {
                    Step = 2
                });

                // mark as complete
                var complete = await tracker.CompleteAsync(request.Id, new CompleteTrackerRequest
                {
                    ResultType = TrackerRequestResultType.Success
                });

                // delete
                var result = await tracker.RemoveAsync(request.Id);
            }

            // sample for getting notifications using tracker id
            var notifications = await new SDK.Notification(serviceBusConfiguration.TrackerApi, activator).GetByTrackerIdAsync(0);

            // sample for getting user notifications using notification id
            var userNotifications = await new SDK.UserNotification(serviceBusConfiguration.TrackerApi, activator).GetByNotificationIdAsync(1);
        }