Beispiel #1
0
        protected static void SendMessageToNewSaga <TMessage>(ISagaPolicy <TSaga, TMessage> policy, TMessage message, Action <TSaga> consumerAction, Action <TSaga> removeAction)
        {
            TSaga saga;

            if (!policy.CreateSagaWhenMissing(message, out saga))
            {
                return;
            }

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Created saga [{0}] - {1}", typeof(TSaga).ToFriendlyName(), saga.CorrelationId);
            }

            try
            {
                lock (saga)
                    consumerAction(saga);

                if (policy.ShouldSagaBeRemoved(saga))
                {
                    removeAction(saga);
                }
            }
            catch (Exception ex)
            {
                var sex = new SagaException("Saga consumer exception", typeof(TSaga), typeof(TMessage), saga.CorrelationId, ex);
                if (_log.IsErrorEnabled)
                {
                    _log.Error("Existing Saga Exception: ", sex);
                }

                throw sex;
            }
        }