Example #1
0
        public void Start(IServiceBus bus)
        {
            _bus        = bus;
            _controlBus = bus.ControlBus;

            bus.Configure(pipelineConfigurator =>
            {
                foreach (WorkerConnector connector in _connectors)
                {
                    try
                    {
                        ISubscriptionReference subscription = connector.Connect(pipelineConfigurator, this);
                        _subscriptions.Add(subscription);
                    }
                    catch (Exception)
                    {
                        StopAllSubscriptions();
                        throw;
                    }
                }

                return(() => true);
            });

            _scheduler.Schedule(TimeSpan.Zero, _publishInterval, _fiber, PublishWorkerAvailability);
        }
        /// <summary>
        /// Adds a message handler to the service bus for handling a specific type of message
        /// </summary>
        /// <typeparam name="T">The message type to handle, often inferred from the callback specified</typeparam>
        /// <param name="bus"></param>
        /// <param name="handler">The callback to invoke when messages of the specified type arrive on the service bus</param>
        public static UnsubscribeAction SubscribeHandlerSelector <T>(this IServiceBus bus, HandlerSelector <T> handler)
            where T : class
        {
            var connector = new HandlerSubscriptionConnector <T>();

            return(bus.Configure(x => connector.Connect(x, handler)));
        }
        /// <summary>
        /// Connects any consumers for the component to the message dispatcher
        /// </summary>
        /// <param name="bus"></param>
        /// <param name="instance"></param>
        public static UnsubscribeAction SubscribeInstance([NotNull] this IServiceBus bus, [NotNull] object instance)
        {
            Guard.AgainstNull(instance, "instance", "A null instance cannot be subscribed");

            InstanceConnector connector = InstanceConnectorCache.GetInstanceConnector(instance.GetType());

            return(bus.Configure(x => connector.Connect(x, instance)));
        }
        /// <summary>
        /// Connects any consumers for the component to the message dispatcher
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="bus"></param>
        /// <param name="instance"></param>
        public static UnsubscribeAction SubscribeInstance <T>([NotNull] this IServiceBus bus, [NotNull] T instance)
            where T : class
        {
            Guard.AgainstNull(instance, "instance", "A null instance cannot be subscribed");

            InstanceConnector connector = InstanceConnectorCache.GetInstanceConnector <T>();

            return(bus.Configure(x => connector.Connect(x, instance)));
        }
Example #5
0
        public static UnsubscribeAction SubscribeSagaWorker <TSaga>(this IServiceBus bus, object worker,
                                                                    ISagaRepository <TSaga> sagaRepository)
            where TSaga : class, ISaga
        {
            Guard.AgainstNull(worker, "worker", "A null saga worker was specified");

            SagaWorkerConnector connector = new SagaWorkerConnector <TSaga>(sagaRepository);

            return(bus.Configure(x => connector.Connect(x, worker)));
        }
Example #6
0
        public void Start(IServiceBus bus)
        {
            _bus = bus;
            _unregisterAction = _bus.Configure(x =>
            {
                UnregisterAction unregisterAction = x.Register(this);

                return(() => unregisterAction());
            });
        }
        public static UnsubscribeAction SubscribeStateMachineSaga <TInstance>(
            this IServiceBus bus, StateMachine <TInstance> stateMachine, ISagaRepository <TInstance> sagaRepository)
            where TInstance : class, SagaStateMachineInstance
        {
            var stateMachineSagaRepositoryConfigurator =
                new StateMachineSagaRepositoryConfiguratorImpl <TInstance>(stateMachine, sagaRepository);

            StateMachineSagaRepository <TInstance> repository = stateMachineSagaRepositoryConfigurator.Configure();

            var connector = new StateMachineConnector <TInstance>(stateMachine, repository);

            return(bus.Configure(x => connector.Connect(x)));
        }
        IRequest <TRequest> Build(IServiceBus bus)
        {
            UnsubscribeAction unsubscribeAction = bus.Configure(configurator =>
            {
                UnsubscribeAction seed = () => true;

                return(_handlers.Aggregate(seed, (x, handlerConfigurator) => x + handlerConfigurator(configurator)));
            });

            _request.SetUnsubscribeAction(unsubscribeAction);

            return(_request);
        }
Example #9
0
        /// <summary>
        /// Connects the saga to the service bus
        /// </summary>
        /// <typeparam name="TSaga">The consumer type</typeparam>
        /// <param name="bus"></param>
        /// <param name="sagaRepository"></param>
        public static UnsubscribeAction SubscribeSaga <TSaga>(this IServiceBus bus, ISagaRepository <TSaga> sagaRepository)
            where TSaga : class, ISaga
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Saga: {0}", typeof(TSaga));
            }

            Guard.AgainstNull(sagaRepository, "sagaRepository", "A saga repository must be specified");

            var connector = new SagaConnector <TSaga>(sagaRepository);

            return(bus.Configure(x => connector.Connect(x)));
        }
Example #10
0
        public IAsyncRequest <TRequest> Build(IServiceBus bus)
        {
            _request.SetTimeout(Timeout);
            if (TimeoutHandler != null)
            {
                _request.SetTimeoutHandler(TimeoutHandler);
            }

            UnsubscribeAction unsubscribeAction = bus.Configure(x => Handlers.CombineSubscriptions(h => h.Connect(x)));

            _request.SetUnsubscribeAction(unsubscribeAction);

            return(_request);
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                      [NotNull] IConsumerFactory <TConsumer>
                                                                      consumerFactory)
            where TConsumer : class
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using supplied consumer factory)", typeof(TConsumer));
            }

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, consumerFactory)));
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus)
            where TConsumer : class, new()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using default consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(() => new TConsumer());

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, delegateConsumerFactory)));
        }
        public static UnsubscribeAction SubscribeConsumer([NotNull] this IServiceBus bus, [NotNull] Type consumerType,
                                                          [NotNull] Func <Type, object> consumerFactory)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (by type, using object consumer factory)", consumerType);
            }

            object factory = FastActivator.Create(typeof(ObjectConsumerFactory <>), new[] { consumerType },
                                                  new object[] { consumerFactory });

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector(consumerType);

            return(bus.Configure(x => connector.FastInvoke <ConsumerConnector, UnsubscribeAction>("Connect", x, factory)));
        }
        public static UnsubscribeAction SubscribeInterceptingConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                                  [NotNull] Func <TConsumer> consumerFactory, [NotNull] Action <Action> interceptor)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using delegate consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(consumerFactory);

            var interceptingConsumerFactory = new InterceptingConsumerFactory <TConsumer>(delegateConsumerFactory,
                                                                                          interceptor);
            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, interceptingConsumerFactory)));
        }
        void ListenToBus(IServiceBus bus)
        {
            var subscriptionEventListener = new BusSubscriptionEventListener(bus, this);

            _unregister += bus.Configure(x =>
            {
                UnregisterAction unregisterAction = x.Register(subscriptionEventListener);

                return(() => unregisterAction());
            });

            _listeners.Add(subscriptionEventListener);

            IServiceBus controlBus = bus.ControlBus;

            if (controlBus != bus)
            {
                ListenToBus(controlBus);
            }
        }
Example #16
0
        public void Start(IServiceBus bus)
        {
            bus.Configure(pipelineConfigurator =>
            {
                foreach (ISubscriptionBuilder builder in _builders)
                {
                    try
                    {
                        ISubscriptionReference subscription = builder.Subscribe(pipelineConfigurator);
                        _subscriptions.Add(subscription);
                    }
                    catch (Exception)
                    {
                        StopAllSubscriptions();
                        throw;
                    }
                }

                return(() => true);
            });
        }
		public void Start(IServiceBus bus)
		{
			bus.Configure(pipelineConfigurator =>
				{
					foreach (SubscriptionBuilder builder in _builders)
					{
						try
						{
							ISubscriptionReference subscription = builder.Subscribe(pipelineConfigurator);
							_subscriptions.Add(subscription);
						}
						catch (Exception)
						{
							StopAllSubscriptions();
							throw;
						}
					}

					return () => true;
				});
		}
Example #18
0
        public void Start(IServiceBus bus)
        {
            _bus        = bus;
            _controlBus = bus.ControlBus;

            bus.Configure(pipelineConfigurator =>
            {
                foreach (DistributorConnector connector in _connectors)
                {
                    try
                    {
                        ISubscriptionReference subscription = connector.Connect(pipelineConfigurator, this);
                        _subscriptions.Add(subscription);
                    }
                    catch (Exception)
                    {
                        StopAllSubscriptions();
                        throw;
                    }
                }

                return(() => true);
            });
        }
 public UnsubscribeAction Configure(Func <IInboundPipelineConfigurator, UnsubscribeAction> configure)
 {
     return(_bus.Configure(configure));
 }
		void ListenToBus(IServiceBus bus)
		{
			var subscriptionEventListener = new BusSubscriptionEventListener(bus, this);

			_unregister += bus.Configure(x =>
				{
					UnregisterAction unregisterAction = x.Register(subscriptionEventListener);

					return () => unregisterAction();
				});

			_listeners.Add(subscriptionEventListener);

			IServiceBus controlBus = bus.ControlBus;
			if (controlBus != bus)
			{
				ListenToBus(controlBus);
			}
		}