示例#1
0
 public CompensableAttribute(string compensationMethod, int retryDelayInMilliseconds = 0, int timeout = 0, int retries = 0)
 {
     _omegaContext           = (OmegaContext)ServiceLocator.Current.GetInstance(typeof(OmegaContext));
     _compensableInterceptor = (IEventAwareInterceptor)ServiceLocator.Current.GetInstance(typeof(IEventAwareInterceptor));
     _recoveryPolicy         = (IRecoveryPolicy)ServiceLocator.Current.GetInstance(typeof(IRecoveryPolicy));
     _compensationContext    =
         (CompensationContext)ServiceLocator.Current.GetInstance(typeof(CompensationContext));
     _messageFormat           = (IMessageSerializer)ServiceLocator.Current.GetInstance(typeof(IMessageSerializer));
     Retries                  = retries;
     CompensationMethod       = compensationMethod;
     RetryDelayInMilliseconds = retryDelayInMilliseconds;
     Timeout                  = timeout;
     _parenttxId              = _omegaContext.GetGlobalTxId();
 }
        public void BeforeApply(IEventAwareInterceptor compensableInterceptor, OmegaContext omegaContext, string parentTxId, int retries, int timeout, string methodName, params object[] parameters)
        {
            _logger.Debug($"Intercepting compensable method {methodName} with context {omegaContext}");

            var response = compensableInterceptor.PreIntercept(parentTxId, methodName, timeout,
                                                               "", retries, parameters);

            if (!response.Aborted)
            {
                return;
            }
            var abortedLocalTxId = omegaContext.GetLocalTxId();

            omegaContext.SetGlobalTxId(parentTxId);
            throw new InvalidTransactionException($"Abort sub transaction {abortedLocalTxId}  because global transaction{omegaContext.GetLocalTxId()} has already aborted.");
        }
 public void ErrorApply(IEventAwareInterceptor compensableInterceptor, string parentTxId, string methodName, System.Exception throwable)
 {
     compensableInterceptor.OnError(parentTxId, methodName, throwable);
 }
 public void AfterApply(IEventAwareInterceptor compensableInterceptor, string parentTxId, string methodName)
 {
     compensableInterceptor.PostIntercept(parentTxId, methodName);
 }