Ejemplo n.º 1
0
        private void Recovery(SagaTxs sagaTxs)
        {
            while (sagaTxs.Sagas.TryPop(out SagaTx tx))
            {
                try
                {
                    var    response = tx.sagaInput;
                    string channel, router, method;
                    channel = tx.sagaInput[Eng.NAMESPACE];
                    router  = tx.sagaInput[Eng.CLASS];
                    method  = tx.recover;
                    response.Add("sagaRlt", tx.sagaRlt);

                    if (response.ContainsKey("TraceId"))
                    {
                        response.Remove("TraceId");
                    }

                    if (response.ContainsKey("PreTraceId"))
                    {
                        response.Remove("PreTraceId");
                    }
                    this.InvokeProcessor(channel, router, method, response);
#if DEBUG
                    Log.Log.WriteLine($"channel:{channel},router:{router},method:{method}       SagaRecovery!");
#endif
                }
                catch (Exception ex)
                {
                    Log.Log.Error(ex, typeof(DTransactionManager));
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 开始Saga
 /// </summary>
 /// <param name="globalTraceId">全局追踪ID</param>
 /// <param name="recover">恢复方法</param>
 /// <param name="sagaInput">输入</param>
 /// <param name="executionTimeSpan">预估整个任务执行时间长度</param>
 /// <returns></returns>
 public dynamic SagaStarted(string globalTraceId, string recover, Dictionary <string, string> sagaInput, double executionTimeSpan)
 {
     DTransactionManager.Sagas.TryGetValue(globalTraceId, out SagaTxs sagaTxs);
     if (sagaTxs == null)
     {
         sagaTxs = new SagaTxs();
         sagaTxs.Sagas.Push(new SagaTx()
         {
             sagaGlobalId = globalTraceId,
             recover      = recover,
             sagaInput    = sagaInput,
             sagaId       = globalTraceId
         });
         sagaTxs.Deadline = DateTime.Now.AddMilliseconds(executionTimeSpan);
         DTransactionManager.Sagas.TryAdd(globalTraceId, sagaTxs);
     }
     return(true);
 }
Ejemplo n.º 3
0
        private void Recovery(SagaTxs sagaTxs)
        {
            var rpc = Loader.IocLoader.Resolve <IRpcConnector>();

            if (rpc != null)
            {
                while (sagaTxs.Sagas.TryPop(out SagaTx tx))
                {
                    try
                    {
                        var    response = tx.sagaInput;
                        string channel, router, method;
                        channel = tx.sagaInput[Eng.NAMESPACE];
                        router  = tx.sagaInput[Eng.CLASS];
                        method  = tx.recover;
                        response.Add("sagaRlt", tx.sagaRlt);

                        if (response.ContainsKey("TraceId"))
                        {
                            response.Remove("TraceId");
                        }

                        if (response.ContainsKey("PreTraceId"))
                        {
                            response.Remove("PreTraceId");
                        }
                        #region 路由信息

                        if (response.ContainsKey("channel"))
                        {
                            response["channel"] = channel;
                        }
                        else
                        {
                            response.Add("channel", channel);
                        }

                        if (response.ContainsKey("router"))
                        {
                            response["router"] = router;
                        }
                        else
                        {
                            response.Add("router", router);
                        }

                        if (response.ContainsKey("method"))
                        {
                            response["method"] = method;
                        }
                        else
                        {
                            response.Add("method", method);
                        }
                        #endregion
                        rpc.BrokerDns(response);
#if DEBUG
                        Log.Log.WriteLine($"channel:{channel},router:{router},method:{method}       SagaRecovery!");
#endif
                    }
                    catch (Exception ex)
                    {
                        Log.Log.Error(ex, typeof(DTransactionManager));
                    }
                }
            }
        }