示例#1
0
        public bool Transport_OnMessageArrived(CurrentMessageInformation msg)
        {
            var consumers = GatherConsumers(msg);

            if (consumers.Length == 0)
            {
                logger.ErrorFormat("Got message {0}, but had no consumers for it", msg.Message);
                return(false);
            }
            try
            {
                currentMessage = msg.Message;

                foreach (var consumer in consumers)
                {
                    logger.DebugFormat("Invoking consume on {0} for message {1}, from '{2}' to '{3}'",
                                       consumer,
                                       msg.Message,
                                       msg.Source,
                                       msg.Destination);

                    var sp = Stopwatch.StartNew();
                    try
                    {
                        reflection.InvokeConsume(consumer, msg.Message);
                    }
                    catch (Exception e)
                    {
                        if (logger.IsDebugEnabled)
                        {
                            var message = string.Format("Consumer {0} failed to process message {1}",
                                                        consumer,
                                                        msg.Message
                                                        );
                            logger.Debug(message, e);
                        }
                        throw;
                    }
                    finally
                    {
                        sp.Stop();
                        var elapsed = sp.Elapsed;
                        logger.DebugFormat("Consumer {0} finished processing {1} in {2}", consumer, msg.Message, elapsed);
                    }
                    var sagaEntity = consumer as IAccessibleSaga;
                    if (sagaEntity == null)
                    {
                        continue;
                    }
                    PersistSagaInstance(sagaEntity);
                }
                return(true);
            }
            finally
            {
                currentMessage = null;

                foreach (var consumer in consumers)
                {
                    serviceLocator.Release(consumer);
                }
            }
        }