public MessagePerformanceMetric(DateTime receivedTime, IncomingMessageContext context)
        {
            Mandate.ParameterNotNull(context, "context");
            var headers = context.TransportMessage.Headers;

            if (headers.ContainsKey(HeaderKeys.FailureDetails))
            {
                TimeToProcess = TimeSpan.Zero;
                TimeToDeliver = TimeSpan.Zero;
                Error = true;
            }
            else
            {
                DateTime completedTime = headers[HeaderKeys.CompletedTime].ToUtcDateTime();
                DateTime sentTime = headers[HeaderKeys.SentTime].ToUtcDateTime();

                TimeToProcess = completedTime - receivedTime;
                TimeToDeliver = receivedTime - sentTime;
                Error = false;

                if (TimeToDeliver < TimeSpan.Zero)
                    TimeToDeliver = TimeSpan.Zero;

                if (TimeToProcess < TimeSpan.Zero)
                    TimeToProcess = TimeSpan.Zero;
            }
        }
Esempio n. 2
0
 public virtual void ProcessMessage(IncomingMessageContext incomingContext)
 {
     try
     {
         currentMessageBeingProcessed.Value = incomingContext;
         incomingContext.Process(incomingPipeline);
     }
     finally
     {
         currentMessageBeingProcessed.Value = IncomingMessageContext.Null;
     }
 }
Esempio n. 3
0
 protected virtual void ProcessCommand(object message)
 {
     try
     {
         using (IContainer childContainer = container.BeginLifetimeScope())
         {
             ServiceLocator.Current.SetCurrentLifetimeScope(childContainer);
             var incomingContext = new IncomingMessageContext(message, childContainer);
             messageTransport.ProcessMessage(incomingContext);
         }
     }
     finally
     {
         ServiceLocator.Current.SetCurrentLifetimeScope(null);
     }
 }
        public void Add(DateTime receivedTime, IncomingMessageContext incomingMessage)
        {
            try
            {
                var metric = new MessagePerformanceMetric(receivedTime, incomingMessage);

                lock (syncLock)
                {
                    performanceMetrics.Add(metric);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error while adding performance metric. {0}", ex.GetFullExceptionMessage());
            }
        }
Esempio n. 5
0
 public virtual void ProcessMessage(IncomingMessageContext incomingContext)
 {
     try
     {
         using (var scope = StartTransactionScope())
         {
             currentMessageBeingProcessed.Value = incomingContext;
             incomingContext.Process(incomingPipeline);
             scope.Complete();
         }
     }
     finally
     {
         currentMessageBeingProcessed.Value = IncomingMessageContext.Null;
     }
 }
Esempio n. 6
0
        public void HandleCallback(IncomingMessageContext context)
        {
            if (context.CorrelationId == Guid.Empty)
                return;

            Logger.Debug("Handling callback for message {0} with correlation ID {1}", context.MessageId, context.CorrelationId);

            BusAsyncResult busAsyncResult;

            lock (MessageIdToAsyncResultLookup)
            {
                MessageIdToAsyncResultLookup.TryGetValue(context.CorrelationId, out busAsyncResult);
                MessageIdToAsyncResultLookup.Remove(context.CorrelationId);
            }

            if (busAsyncResult == null)
            {
                Logger.Debug("No callback is registered with correlation ID {0}", context.CorrelationId);
                return;
            }

            int statusCode = 0;

            if (context.IsControlMessage())
            {
                HeaderValue errorCodeHeader;

                if (context.TryGetHeaderValue(HeaderKeys.ReturnErrorCode, out errorCodeHeader))
                {
                    statusCode = Int32.Parse(errorCodeHeader.Value);
                }
            }

            Logger.Debug("Calling callback for correlation ID {0}", context.CorrelationId);
            busAsyncResult.Complete(statusCode, context.Message);
        }
Esempio n. 7
0
        private void ProcessCommandWithNewLifetimeScope(object message)
        {
            try
            {
                Logger.Debug("Process command with new lifetimeScope");

                using (IContainer childContainer = container.BeginLifetimeScope())
                {
                    ServiceLocator.Current.SetCurrentLifetimeScope(childContainer);
                    var incomingContext = new IncomingMessageContext(message, childContainer);
                    messageTransport.ProcessMessage(incomingContext);
                }
            }
            finally
            {
                ServiceLocator.Current.SetCurrentLifetimeScope(null);
            }
        }
Esempio n. 8
0
 private void ProcessCommandWithExistingLifetimeScope(object message)
 {
     Logger.Debug("Process command with existing lifetimeScope");
     var incomingContext = new IncomingMessageContext(message, ServiceLocator.Current);
     messageTransport.ProcessMessage(incomingContext);
 }
Esempio n. 9
0
        protected virtual void MessageReceived(TransportMessage transportMessage)
        {
            Logger.Debug("Message {0} with correlation Id {1} received", transportMessage.MessageId, transportMessage.CorrelationId);

            using (IContainer childContainer = container.BeginLifetimeScope())
            {
                try
                {
                    ServiceLocator.Current.SetCurrentLifetimeScope(childContainer);
                    var incomingContext = new IncomingMessageContext(transportMessage, childContainer);
                    ProcessMessage(incomingContext);
                }
                finally
                {
                    ServiceLocator.Current.SetCurrentLifetimeScope(null);
                }
            }
        }
Esempio n. 10
0
 protected virtual void EnqueOutgoingMessage(OutgoingMessageContext outgoingMessageContext, IncomingMessageContext currentContext)
 {
     outgoingMessageContext.SetUserName(currentContext.UserName);
     currentContext.Enqueue(outgoingMessageContext);
 }