public DistributeMessageEventArgs(PipelineEvent pipelineEvent, IQueue destinationQueue,
		                                  TransportMessage transportMessage)
            : base(pipelineEvent)
        {
            DestinationQueue = destinationQueue;
            TransportMessage = transportMessage;
        }
Exemple #2
0
 public DistributeMessageEventArgs(PipelineEvent pipelineEvent, IQueue destinationQueue,
                                   TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     DestinationQueue = destinationQueue;
     TransportMessage = transportMessage;
 }
        private void InvokeHandler(IServiceBus bus, IMessageHandler handler, TransportMessage transportMessage,
                                   object message, PipelineEvent pipelineEvent, Type messageType)
        {
            var state       = pipelineEvent.Pipeline.State;
            var contextType = typeof(HandlerContext <>).MakeGenericType(new[] { messageType });
            var method      = handler.GetType().GetMethod("ProcessMessage", new[] { contextType });

            Guard.Against <ProcessMessageMethodMissingException>(method == null,
                                                                 string.Format(
                                                                     ESBResources.ProcessMessageMethodMissingException,
                                                                     handler.GetType().FullName,
                                                                     transportMessage.MessageType));

            if (_log.IsTraceEnabled)
            {
                _log.Trace(string.Format(ESBResources.TraceCorrelationIdReceived, transportMessage.CorrelationId));

                foreach (var header in transportMessage.Headers)
                {
                    _log.Trace(string.Format(ESBResources.TraceTransportHeaderReceived, header.Key, header.Value));
                }

                _log.Trace(string.Format(ESBResources.MessageHandlerInvoke,
                                         transportMessage.MessageType,
                                         transportMessage.MessageId,
                                         handler.GetType().FullName));
            }

            try
            {
                var handlerContext = Activator.CreateInstance(contextType, new[]
                {
                    bus, transportMessage, message, state.GetActiveState()
                });

                pipelineEvent.Pipeline.State.SetHandlerContext((IMessageSender)handlerContext);

                method.Invoke(handler, new[]
                {
                    handlerContext
                });
            }
            catch (Exception ex)
            {
                var exception = ex.TrimLeading <TargetInvocationException>();

                bus.Events.OnHandlerException(
                    this,
                    new HandlerExceptionEventArgs(
                        pipelineEvent,
                        handler,
                        transportMessage,
                        message,
                        state.GetWorkQueue(),
                        state.GetErrorQueue(),
                        exception));

                throw exception;
            }
        }
Exemple #4
0
        private void RaiseEvent(PipelineEvent @event, bool ignoreAbort = false)
        {
            var observersForEvent = (from e in _observedEvents
                                     where e.Key == @event.GetType().FullName
                                     select e.Value).SingleOrDefault();

            if (observersForEvent == null || observersForEvent.Count == 0)
            {
                return;
            }

            foreach (var observer in observersForEvent)
            {
                _log.Verbose(string.Format(RaisingPipelineEvent, @event.Name, StageName, observer.GetType().FullName));

                observer.GetType().InvokeMember("Execute",
                                                BindingFlags.FlattenHierarchy | BindingFlags.Instance |
                                                BindingFlags.InvokeMethod | BindingFlags.Public, null,
                                                observer,
                                                new[] { @event });

                if (Aborted && !ignoreAbort)
                {
                    return;
                }
            }
        }
Exemple #5
0
        public void Register(PipelineEvent pipelineEventToRegister)
        {
            Guard.AgainstNull(pipelineEventToRegister, "pipelineEventToRegister");

            var index = eventsToExecute.IndexOf(pipelineEvent);

            eventsToExecute.Insert(index, pipelineEventToRegister);
        }
        public PipelineStage WithEvent(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            events.Add(pipelineEvent);

            return(this);
        }
        public DeserializationExceptionEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue,
		                                         Exception exception)
            : base(pipelineEvent)
        {
            WorkQueue = workQueue;
            ErrorQueue = errorQueue;
            Exception = exception;
        }
        public bool IsSatisfiedBy(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            return(_assessors.All(assessor => assessor.Invoke(pipelineEvent))
                   &&
                   _specifications.All(specification => specification.IsSatisfiedBy(pipelineEvent)));
        }
        public bool IsSatisfiedBy(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            return _assessors.All(assessor => assessor.Invoke(pipelineEvent))
                   &&
                   _specifications.All(specification => specification.IsSatisfiedBy(pipelineEvent));
        }
 public DeserializationExceptionEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue,
                                          Exception exception)
     : base(pipelineEvent)
 {
     WorkQueue  = workQueue;
     ErrorQueue = errorQueue;
     Exception  = exception;
 }
        public PipelineStage Register(PipelineEvent pipelineEventToRegister)
        {
            Guard.AgainstNull(pipelineEventToRegister, "pipelineEventToRegister");

            var index = eventsToExecute.IndexOf(pipelineEvent);

            eventsToExecute.Insert(index + 1, pipelineEventToRegister);

            return(pipelineStage);
        }
        public HandlerExceptionEventArgs(PipelineEvent pipelineEvent,
		                                 TransportMessage transportMessage, object message, IQueue workQueue,
		                                 IQueue errorQueue, Exception exception)
            : base(pipelineEvent)
        {
            TransportMessage = transportMessage;
            Message = message;
            WorkQueue = workQueue;
            ErrorQueue = errorQueue;
            Exception = exception;
        }
Exemple #13
0
 public HandlerExceptionEventArgs(PipelineEvent pipelineEvent,
                                  TransportMessage transportMessage, object message, IQueue workQueue,
                                  IQueue errorQueue, Exception exception)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
     Message          = message;
     WorkQueue        = workQueue;
     ErrorQueue       = errorQueue;
     Exception        = exception;
 }
        public MessageNotHandledEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue, TransportMessage transportMessage, object message)
            : base(pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");
            Guard.AgainstNull(workQueue, "workQueue");
            Guard.AgainstNull(errorQueue, "errorQueue");
            Guard.AgainstNull(transportMessage, "transportMessage");
            Guard.AgainstNull(message, "message");

            WorkQueue        = workQueue;
            ErrorQueue       = errorQueue;
            TransportMessage = transportMessage;
            Message          = message;
        }
        public MessageNotHandledEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue, TransportMessage transportMessage, object message)
            : base(pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");
            Guard.AgainstNull(workQueue, "workQueue");
            Guard.AgainstNull(errorQueue, "errorQueue");
            Guard.AgainstNull(transportMessage, "transportMessage");
            Guard.AgainstNull(message, "message");

            WorkQueue = workQueue;
            ErrorQueue = errorQueue;
            TransportMessage = transportMessage;
            Message = message;
        }
        public MessageHandlerInvokeResult Invoke(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            var state   = pipelineEvent.Pipeline.State;
            var bus     = state.GetServiceBus();
            var message = state.GetMessage();
            var handler = bus.Configuration.MessageHandlerFactory.GetHandler(message);

            if (handler == null)
            {
                return(MessageHandlerInvokeResult.InvokeFailure());
            }

            try
            {
                var transportMessage = state.GetTransportMessage();
                var messageType      = message.GetType();
                var contextType      = typeof(HandlerContext <>).MakeGenericType(messageType);
                var method           = handler.GetType().GetMethod("ProcessMessage", new[] { contextType });

                if (method == null)
                {
                    throw new ProcessMessageMethodMissingException(string.Format(
                                                                       ESBResources.ProcessMessageMethodMissingException,
                                                                       handler.GetType().FullName,
                                                                       messageType.FullName));
                }

                var handlerContext = Activator.CreateInstance(contextType, bus, transportMessage, message, state.GetActiveState());

                method.Invoke(handler, new[] { handlerContext });
            }
            finally
            {
                bus.Configuration.MessageHandlerFactory.ReleaseHandler(handler);
            }

            return(MessageHandlerInvokeResult.InvokedHandler(handler));
        }
        public MessageHandlerInvokeResult Invoke(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            var state = pipelineEvent.Pipeline.State;
            var bus = state.GetServiceBus();
            var message = state.GetMessage();
            var handler = bus.Configuration.MessageHandlerFactory.GetHandler(message);

            if (handler == null)
            {
                return MessageHandlerInvokeResult.InvokeFailure();
            }

            try
            {
                var transportMessage = state.GetTransportMessage();
                var messageType = message.GetType();
                var contextType = typeof(HandlerContext<>).MakeGenericType(messageType);
                var method = handler.GetType().GetMethod("ProcessMessage", new[] { contextType });

                if (method == null)
                {
                    throw new ProcessMessageMethodMissingException(string.Format(
                        ESBResources.ProcessMessageMethodMissingException,
                        handler.GetType().FullName,
                        messageType.FullName));
                }

                var handlerContext = Activator.CreateInstance(contextType, bus, transportMessage, message, state.GetActiveState());

                method.Invoke(handler, new[] { handlerContext });
            }
            finally
            {
                bus.Configuration.MessageHandlerFactory.ReleaseHandler(handler);
            }

            return MessageHandlerInvokeResult.InvokedHandler(handler);
        }
 public ITransactionScope Create(PipelineEvent pipelineEvent)
 {
     return _enabled ? new DefaultTransactionScope(_isolationLevel, _timeout) : _nullServiceBusTransactionScope;
 }
 public PipelineEventEventArgs(PipelineEvent pipelineEvent)
 {
     PipelineEvent = pipelineEvent;
 }
Exemple #20
0
 public static Stream GetTransportMessageStream(this PipelineEvent pipelineEvent)
 {
     return(pipelineEvent.Pipeline.State.Get <Stream>(StateKeys.TransportMessageStream));
 }
 public PipelineEventEventArgs(PipelineEvent pipelineEvent)
 {
     PipelineEvent = pipelineEvent;
 }
 public QueueStreamEventArgs(PipelineEvent pipelineEvent, IQueue queue, Stream stream)
     : base(pipelineEvent)
 {
     Queue = queue;
     TransportMessageStream = stream;
 }
 public MessageSerializationEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage, object message)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
     Message = message;
 }
 public QueueMessageEventArgs(PipelineEvent pipelineEvent, IQueue queue, TransportMessage message)
     : base(pipelineEvent)
 {
     Queue = queue;
     TransportMessage = message;
 }
 public RegisterEventAfter(PipelineStage pipelineStage, List <PipelineEvent> eventsToExecute, PipelineEvent pipelineEvent)
 {
     this.pipelineStage   = pipelineStage;
     this.eventsToExecute = eventsToExecute;
     this.pipelineEvent   = pipelineEvent;
 }
Exemple #26
0
 public static void SetMessageBytes(this PipelineEvent pipelineEvent, byte[] bytes)
 {
     pipelineEvent.Pipeline.State.Replace(StateKeys.MessageBytes, bytes);
 }
		public AfterHandleMessageEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, TransportMessage transportMessage)
			: base(pipelineEvent)
		{
			WorkQueue = workQueue;
			TransportMessage = transportMessage;
		}
 public DequeueExceptionEventArgs(PipelineEvent pipelineEvent, IQueue queue, Exception exception)
     : base(pipelineEvent)
 {
     Queue     = queue;
     Exception = exception;
 }
 public AfterHandleMessageEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     WorkQueue = workQueue;
     TransportMessage = transportMessage;
 }
Exemple #30
0
 public static byte[] GetMessageBytes(this PipelineEvent pipelineEvent)
 {
     return(pipelineEvent.Pipeline.State.Get <byte[]>(StateKeys.MessageBytes));
 }
Exemple #31
0
 public BeforeHandleMessageEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
 }
 public IServiceBusTransactionScope Create(PipelineEvent pipelineEvent)
 {
     return(_enabled ? new ServiceBusTransactionScope(_isolationLevel, _timeout) : _nullServiceBusTransactionScope);
 }
Exemple #33
0
 public static void SetMessage(this PipelineEvent pipelineEvent, object message)
 {
     pipelineEvent.Pipeline.State.Replace(StateKeys.Message, message);
 }
Exemple #34
0
 public RegisterEventBefore(List <PipelineEvent> eventsToExecute, PipelineEvent pipelineEvent)
 {
     this.eventsToExecute = eventsToExecute;
     this.pipelineEvent   = pipelineEvent;
 }
 public QueueEmptyEventArgs(PipelineEvent pipelineEvent, IQueue queue)
     : base(pipelineEvent)
 {
     Queue = queue;
 }
Exemple #36
0
        private void RaiseEvent(PipelineEvent @event, bool ignoreAbort = false)
        {
            var observersForEvent = (from e in _observedEvents
                                     where e.Key == @event.GetType().FullName
                                     select e.Value).SingleOrDefault();

            if (observersForEvent == null || observersForEvent.Count == 0)
            {
                return;
            }

            foreach (var observer in observersForEvent)
            {
                _log.Verbose(string.Format(RaisingPipelineEvent, @event.Name, StageName, observer.GetType().FullName));

                observer.GetType().InvokeMember("Execute",
                                                BindingFlags.FlattenHierarchy | BindingFlags.Instance |
                                                BindingFlags.InvokeMethod | BindingFlags.Public, null,
                                                observer,
                                                new[] {@event});

                if (Aborted && !ignoreAbort)
                {
                    return;
                }
            }
        }
Exemple #37
0
 public static object GetMessage(this PipelineEvent pipelineEvent)
 {
     return(pipelineEvent.Pipeline.State.Get <object>(StateKeys.Message));
 }
Exemple #38
0
 public TransportMessageSerializationEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
 }
Exemple #39
0
 public QueueEmptyEventArgs(PipelineEvent pipelineEvent, IQueue queue)
     : base(pipelineEvent)
 {
     Queue = queue;
 }
Exemple #40
0
 public static DateTime GetIgnoreTillDate(this PipelineEvent pipelineEvent)
 {
     return(pipelineEvent.Pipeline.State.Get <DateTime>(StateKeys.IgnoreTillDate));
 }
 public ServiceBusTransactionScope Create(PipelineEvent pipelineEvent)
 {
     return new ServiceBusTransactionScope(isolationLevel, timeout);
 }
 public BeforeDequeueEventArgs(PipelineEvent pipelineEvent, IQueue queue)
     : base(pipelineEvent)
 {
     Queue = queue;
 }
 public DequeueExceptionEventArgs(PipelineEvent pipelineEvent, IQueue queue, Exception exception)
     : base(pipelineEvent)
 {
     Queue = queue;
     Exception = exception;
 }
Exemple #44
0
 public static void SetAvailableWorker(this PipelineEvent pipelineEvent, AvailableWorker value)
 {
     pipelineEvent.Pipeline.State.Replace(StateKeys.AvailableWorker, value);
 }
Exemple #45
0
 public QueueStreamEventArgs(PipelineEvent pipelineEvent, IQueue queue, Stream stream)
     : base(pipelineEvent)
 {
     Queue = queue;
     TransportMessageStream = stream;
 }
 public BeforeHandleMessageEventArgs(PipelineEvent pipelineEvent, TransportMessage transportMessage)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
 }
Exemple #47
0
 public BeforeDequeueEventArgs(PipelineEvent pipelineEvent, IQueue queue)
     : base(pipelineEvent)
 {
     Queue = queue;
 }
Exemple #48
0
 public static IServiceBus GetServiceBus(this PipelineEvent pipelineEvent)
 {
     return(pipelineEvent.Pipeline.State.Get <IServiceBus>());
 }