Пример #1
0
        public Worker(IErrorTracker errorTracker,
                      IReceiveMessages receiveMessages,
                      IActivateHandlers activateHandlers,
                      IStoreSubscriptions storeSubscriptions,
                      ISerializeMessages serializeMessages,
                      IStoreSagaData storeSagaData,
                      IInspectHandlerPipeline inspectHandlerPipeline,
                      string workerThreadName,
                      IHandleDeferredMessage handleDeferredMessage,
                      IMutateIncomingMessages mutateIncomingMessages,
                      IStoreTimeouts storeTimeouts,
                      IEnumerable <IUnitOfWorkManager> unitOfWorkManagers,
                      ConfigureAdditionalBehavior configureAdditionalBehavior,
                      MessageLogger messageLogger)
        {
            this.receiveMessages             = receiveMessages;
            this.serializeMessages           = serializeMessages;
            this.mutateIncomingMessages      = mutateIncomingMessages;
            this.unitOfWorkManagers          = unitOfWorkManagers;
            this.configureAdditionalBehavior = configureAdditionalBehavior;
            this.messageLogger               = messageLogger;
            this.errorTracker                = errorTracker;
            dispatcher                       = new Dispatcher(storeSagaData, activateHandlers, storeSubscriptions, inspectHandlerPipeline, handleDeferredMessage, storeTimeouts);
            dispatcher.UncorrelatedMessage  += RaiseUncorrelatedMessage;
            nullMessageReceivedBackoffHelper = CreateBackoffHelper(configureAdditionalBehavior.BackoffBehavior);

            workerThread = new Thread(MainLoop)
            {
                Name = workerThreadName
            };
            workerThread.Start();

            log.Info("Worker {0} created and inner thread started", WorkerThreadName);
        }
Пример #2
0
        public Worker(IErrorTracker errorTracker,
                      IReceiveMessages receiveMessages,
                      IActivateHandlers activateHandlers,
                      IStoreSubscriptions storeSubscriptions,
                      ISerializeMessages serializeMessages,
                      IStoreSagaData storeSagaData,
                      IInspectHandlerPipeline inspectHandlerPipeline,
                      string workerThreadName,
                      IHandleDeferredMessage handleDeferredMessage,
                      IMutateIncomingMessages mutateIncomingMessages)
        {
            this.receiveMessages        = receiveMessages;
            this.serializeMessages      = serializeMessages;
            this.mutateIncomingMessages = mutateIncomingMessages;
            this.errorTracker           = errorTracker;
            dispatcher = new Dispatcher(storeSagaData, activateHandlers, storeSubscriptions, inspectHandlerPipeline, handleDeferredMessage);
            dispatcher.UncorrelatedMessage += RaiseUncorrelatedMessage;

            workerThread = new Thread(MainLoop)
            {
                Name = workerThreadName
            };
            workerThread.Start();

            log.Info("Worker {0} created and inner thread started", WorkerThreadName);
        }
Пример #3
0
 /// <summary>
 /// Constructs the dispatcher with the specified instances to store and retrieve saga data,
 /// create message handlers, store and retrieve subscriptions, and to inspect and
 /// possibly rearrange the handler pipeline.
 /// </summary>
 public Dispatcher(IStoreSagaData storeSagaData,
                   IActivateHandlers activateHandlers,
                   IStoreSubscriptions storeSubscriptions,
                   IInspectHandlerPipeline inspectHandlerPipeline,
                   IHandleDeferredMessage handleDeferredMessage)
 {
     this.storeSagaData          = storeSagaData;
     this.activateHandlers       = activateHandlers;
     this.storeSubscriptions     = storeSubscriptions;
     this.inspectHandlerPipeline = inspectHandlerPipeline;
     this.handleDeferredMessage  = handleDeferredMessage;
 }
Пример #4
0
 protected override void DoSetUp()
 {
     activateHandlers = new HandlerActivatorForTesting();
     determineMessageOwnership = Mock<IDetermineMessageOwnership>();
     sendMessages = Mock<ISendMessages>();
     serializeMessages = new JsonMessageSerializer();
     storeSagaData = Mock<IStoreSagaData>();
     receiveMessages = new MessageReceiverForTesting(serializeMessages);
     inspectHandlerPipeline = new TrivialPipelineInspector();
     storeSubscriptions = Mock<IStoreSubscriptions>();
     bus = CreateTheBus();
     bus.Start();
 }
Пример #5
0
 protected override void DoSetUp()
 {
     activateHandlers       = new HandlerActivatorForTesting();
     determineDestination   = Mock <IDetermineDestination>();
     sendMessages           = Mock <ISendMessages>();
     serializeMessages      = new JsonMessageSerializer();
     storeSagaData          = Mock <IStoreSagaData>();
     receiveMessages        = new MessageReceiverForTesting(serializeMessages);
     inspectHandlerPipeline = new TrivialPipelineInspector();
     storeSubscriptions     = Mock <IStoreSubscriptions>();
     bus = CreateTheBus();
     bus.Start();
 }
Пример #6
0
        /// <summary>
        /// Constructs the bus with the specified ways of achieving its goals.
        /// </summary>
        /// <param name="activateHandlers">The bus will use this to construct handlers for received messages.</param>
        /// <param name="sendMessages">Will be used to send transport messages when you send, publish, and reply.</param>
        /// <param name="receiveMessages">Will be used to receive transport messages. If the bus is configured to run with multiple threads, this one should be reentrant.</param>
        /// <param name="storeSubscriptions">Will be used to store subscription information. Is only relevant if the bus is a publisher, i.e. it publishes messages and other services assume they can subscribe to its messages.</param>
        /// <param name="storeSagaData">Will be used to store saga data. Is only relevant if one or more handlers are derived from <see cref="Saga"/>.</param>
        /// <param name="determineDestination">Will be used to resolve a destination in cases where the message destination is not explicitly specified as part of a send/subscribe operation.</param>
        /// <param name="serializeMessages">Will be used to serialize and deserialize transport messages.</param>
        /// <param name="inspectHandlerPipeline">Will be called to inspect the pipeline of handlers constructed to handle an incoming message.</param>
        public RebusBus(IActivateHandlers activateHandlers, ISendMessages sendMessages, IReceiveMessages receiveMessages, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, IDetermineDestination determineDestination, ISerializeMessages serializeMessages, IInspectHandlerPipeline inspectHandlerPipeline)
        {
            this.activateHandlers       = activateHandlers;
            this.sendMessages           = sendMessages;
            this.receiveMessages        = receiveMessages;
            this.storeSubscriptions     = storeSubscriptions;
            this.determineDestination   = determineDestination;
            this.serializeMessages      = serializeMessages;
            this.storeSagaData          = storeSagaData;
            this.inspectHandlerPipeline = inspectHandlerPipeline;

            rebusId = Interlocked.Increment(ref rebusIdCounter);

            log.Info("Rebus bus created");
        }
Пример #7
0
 /// <summary>
 /// Constructs the dispatcher with the specified instances to store and retrieve saga data,
 /// create message handlers, store and retrieve subscriptions, and to inspect and
 /// possibly rearrange the handler pipeline.
 /// </summary>
 public Dispatcher(IStoreSagaData storeSagaData,
                   IActivateHandlers activateHandlers,
                   IStoreSubscriptions storeSubscriptions,
                   IInspectHandlerPipeline inspectHandlerPipeline,
                   IHandleDeferredMessage handleDeferredMessage,
                   IStoreTimeouts storeTimeouts)
 {
     this.storeSagaData          = storeSagaData;
     this.activateHandlers       = activateHandlers;
     this.storeSubscriptions     = storeSubscriptions;
     this.inspectHandlerPipeline = inspectHandlerPipeline;
     this.handleDeferredMessage  = handleDeferredMessage;
     this.storeTimeouts          = storeTimeouts;
     sagaDataIdPropertyName      = Reflect.Path <ISagaData>(s => s.Id);
     sagaDataPropertyName        = Reflect.Path <Saga <ISagaData> >(s => s.Data);
 }
Пример #8
0
 protected Worker CreateWorker(IReceiveMessages receiveMessages, IActivateHandlers activateHandlers, 
     IInspectHandlerPipeline inspectHandlerPipeline = null,
     IEnumerable<IUnitOfWorkManager> unitOfWorkManagers = null,
     IErrorTracker errorTracker = null)
 {
     return new Worker(errorTracker ??  new ErrorTracker("error"),
                       receiveMessages,
                       activateHandlers,
                       new InMemorySubscriptionStorage(),
                       new JsonMessageSerializer(),
                       new SagaDataPersisterForTesting(),
                       inspectHandlerPipeline ?? new TrivialPipelineInspector(),
                       "Just some test worker",
                       new DeferredMessageHandlerForTesting(),
                       new IncomingMessageMutatorPipelineForTesting(),
                       null,
                       unitOfWorkManagers ?? new IUnitOfWorkManager[0],
                       new ConfigureAdditionalBehavior());
 }
Пример #9
0
 protected Worker CreateWorker(IReceiveMessages receiveMessages, IActivateHandlers activateHandlers,
                               IInspectHandlerPipeline inspectHandlerPipeline      = null,
                               IEnumerable <IUnitOfWorkManager> unitOfWorkManagers = null,
                               IErrorTracker errorTracker = null)
 {
     return(new Worker(errorTracker ?? new ErrorTracker("error"),
                       receiveMessages,
                       activateHandlers,
                       new InMemorySubscriptionStorage(),
                       new JsonMessageSerializer(),
                       new SagaDataPersisterForTesting(),
                       inspectHandlerPipeline ?? new TrivialPipelineInspector(),
                       "Just some test worker",
                       new DeferredMessageHandlerForTesting(),
                       new IncomingMessageMutatorPipelineForTesting(),
                       null,
                       unitOfWorkManagers ?? new IUnitOfWorkManager[0],
                       new ConfigureAdditionalBehavior()));
 }
Пример #10
0
        /// <summary>
        /// Constructs the bus with the specified ways of achieving its goals.
        /// </summary>
        /// <param name="activateHandlers">The bus will use this to construct handlers for received messages.</param>
        /// <param name="sendMessages">Will be used to send transport messages when you send, publish, and reply.</param>
        /// <param name="receiveMessages">Will be used to receive transport messages. If the bus is configured to run with multiple threads, this one should be reentrant.</param>
        /// <param name="storeSubscriptions">Will be used to store subscription information. Is only relevant if the bus is a publisher, i.e. it publishes messages and other services assume they can subscribe to its messages.</param>
        /// <param name="storeSagaData">Will be used to store saga data. Is only relevant if one or more handlers are derived from <see cref="Saga"/>.</param>
        /// <param name="determineDestination">Will be used to resolve a destination in cases where the message destination is not explicitly specified as part of a send/subscribe operation.</param>
        /// <param name="serializeMessages">Will be used to serialize and deserialize transport messages.</param>
        /// <param name="inspectHandlerPipeline">Will be called to inspect the pipeline of handlers constructed to handle an incoming message.</param>
        /// <param name="errorTracker">Will be used to track failed delivery attempts.</param>
        public RebusBus(IActivateHandlers activateHandlers, ISendMessages sendMessages, IReceiveMessages receiveMessages, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, IDetermineDestination determineDestination, ISerializeMessages serializeMessages, IInspectHandlerPipeline inspectHandlerPipeline, IErrorTracker errorTracker)
        {
            this.activateHandlers       = activateHandlers;
            this.sendMessages           = sendMessages;
            this.receiveMessages        = receiveMessages;
            this.storeSubscriptions     = storeSubscriptions;
            this.determineDestination   = determineDestination;
            this.serializeMessages      = serializeMessages;
            this.storeSagaData          = storeSagaData;
            this.inspectHandlerPipeline = inspectHandlerPipeline;
            this.errorTracker           = errorTracker;

            batch   = new RebusBatchOperations(determineDestination, storeSubscriptions, this);
            routing = new RebusRouting(this);

            rebusId = Interlocked.Increment(ref rebusIdCounter);

            log.Info("Rebus bus created");
        }
Пример #11
0
        /// <summary>
        /// Constructs the bus with the specified ways of achieving its goals.
        /// </summary>
        /// <param name="activateHandlers">The bus will use this to construct handlers for received messages.</param>
        /// <param name="sendMessages">Will be used to send transport messages when you send, publish, and reply.</param>
        /// <param name="receiveMessages">Will be used to receive transport messages. If the bus is configured to run with multiple threads, this one should be reentrant.</param>
        /// <param name="storeSubscriptions">Will be used to store subscription information. Is only relevant if the bus is a publisher, i.e. it publishes messages and other services assume they can subscribe to its messages.</param>
        /// <param name="storeSagaData">Will be used to store saga data. Is only relevant if one or more handlers are derived from <see cref="Saga"/>.</param>
        /// <param name="determineMessageOwnership">Will be used to resolve a destination in cases where the message destination is not explicitly specified as part of a send/subscribe operation.</param>
        /// <param name="serializeMessages">Will be used to serialize and deserialize transport messages.</param>
        /// <param name="inspectHandlerPipeline">Will be called to inspect the pipeline of handlers constructed to handle an incoming message.</param>
        /// <param name="errorTracker">Will be used to track failed delivery attempts.</param>
        /// <param name="storeTimeouts">Optionally provides an internal timeout manager to be used instead of sending timeout requests to an external timeout manager</param>
        /// <param name="configureAdditionalBehavior"></param>
        public RebusBus(
            IActivateHandlers activateHandlers, ISendMessages sendMessages, IReceiveMessages receiveMessages, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData,
            IDetermineMessageOwnership determineMessageOwnership, ISerializeMessages serializeMessages, IInspectHandlerPipeline inspectHandlerPipeline, IErrorTracker errorTracker,
            IStoreTimeouts storeTimeouts, ConfigureAdditionalBehavior configureAdditionalBehavior)
        {
            this.activateHandlers            = activateHandlers;
            this.sendMessages                = sendMessages;
            this.receiveMessages             = receiveMessages;
            this.storeSubscriptions          = storeSubscriptions;
            this.determineMessageOwnership   = determineMessageOwnership;
            this.serializeMessages           = serializeMessages;
            this.storeSagaData               = storeSagaData;
            this.inspectHandlerPipeline      = inspectHandlerPipeline;
            this.errorTracker                = errorTracker;
            this.storeTimeouts               = storeTimeouts;
            this.configureAdditionalBehavior = configureAdditionalBehavior;

            batch   = new RebusBatchOperations(determineMessageOwnership, storeSubscriptions, this);
            routing = new RebusRouting(this);

            rebusId       = Interlocked.Increment(ref rebusIdCounter);
            continuations = new RebusSynchronizationContext();

            log.Info("Rebus bus {0} created", rebusId);

            if (storeTimeouts == null)
            {
                var timeoutManagerEndpointAddress = RebusConfigurationSection
                                                    .GetConfigurationValueOrDefault(s => s.TimeoutManagerAddress, "rebus.timeout");

                log.Info("Using external timeout manager with input queue '{0}'", timeoutManagerEndpointAddress);
                timeoutManagerAddress = timeoutManagerEndpointAddress;
            }
            else
            {
                log.Info("Using internal timeout manager");
                timeoutManagerAddress = this.receiveMessages.InputQueueAddress;
                dueTimeoutScheduler   = new DueTimeoutScheduler(storeTimeouts, new DeferredMessageReDispatcher(this));
            }
        }
Пример #12
0
 /// <summary>
 /// Uses the specified implementation of <see cref="IInspectHandlerPipeline"/>
 /// </summary>
 public void Use(IInspectHandlerPipeline inspector)
 {
     Backbone.InspectHandlerPipeline = inspector;
 }
Пример #13
0
 /// <summary>
 /// Uses the specified implementation of <see cref="IInspectHandlerPipeline"/>
 /// </summary>
 public void Use(IInspectHandlerPipeline inspector)
 {
     Backbone.InspectHandlerPipeline = inspector;
 }
Пример #14
0
        public Worker(
            IErrorTracker errorTracker,
            IReceiveMessages receiveMessages,
            IActivateHandlers activateHandlers,
            IStoreSubscriptions storeSubscriptions,
            ISerializeMessages serializeMessages,
            IStoreSagaData storeSagaData,
            IInspectHandlerPipeline inspectHandlerPipeline,
            string workerThreadName,
            IHandleDeferredMessage handleDeferredMessage,
            IMutateIncomingMessages mutateIncomingMessages,
            IStoreTimeouts storeTimeouts,
            IEnumerable<IUnitOfWorkManager> unitOfWorkManagers,
            ConfigureAdditionalBehavior configureAdditionalBehavior,
            MessageLogger messageLogger,
            RebusSynchronizationContext continuations)
        {
            this.receiveMessages = receiveMessages;
            this.serializeMessages = serializeMessages;
            this.mutateIncomingMessages = mutateIncomingMessages;
            this.unitOfWorkManagers = unitOfWorkManagers;
            this.configureAdditionalBehavior = configureAdditionalBehavior;
            this.messageLogger = messageLogger;
            this.continuations = continuations;
            this.errorTracker = errorTracker;
            dispatcher = new Dispatcher(storeSagaData, activateHandlers, storeSubscriptions, inspectHandlerPipeline, handleDeferredMessage, storeTimeouts);
            dispatcher.UncorrelatedMessage += RaiseUncorrelatedMessage;
            nullMessageReceivedBackoffHelper = CreateBackoffHelper(configureAdditionalBehavior.BackoffBehavior);

            workerThread = new Thread(MainLoop) { Name = workerThreadName };
            workerThread.Start();

            log.Info("Worker {0} created and inner thread started", WorkerThreadName);
        }