コード例 #1
0
        private static string BrokerDnsInner(Dictionary <string, string> input, Micro micro)
        {
            string output = string.Empty;

            #region 调用链

            var trace = TransmitTrace.SetTraceId(input, micro);

            #endregion
            #region 处理请求
            try
            {
                using (Request request = new Request(micro.Ip, micro.Port))
                {
                    output = request.Invoke(input);
                }
            }
            catch (Exception ex) //如果异常则从缓存中清除 该缓存
            {
                _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                throw ex;
            }
            finally
            {
                TracePool.EnQueue(trace, output);
            }

            #endregion

            return(output);
        }
コード例 #2
0
        private static string BrokerDnsInner(Dictionary <string, string> input, Micro micro)
        {
            if (micro == null)
            {
                return(FailMessage($"未找到服务【{input[Eng.NAMESPACE]}】"));
            }
            string output = string.Empty;

            #region 调用链

            var trace = TransmitTrace.SetTraceId(input, micro);

            #endregion
            #region 处理请求
            try
            {
                using (Request request = new Request(micro.Ip, micro.Port))
                {
                    output = request.Invoke(input);
                }
            }
            catch (Exception ex) //如果异常则从缓存中清除 该缓存
            {
                if (ex is RpcException && ((RpcException)ex).StatusCode == StatusCode.DeadlineExceeded)
                {
                    output = FailMessage(ex.Message);
                }
                else
                {
                    _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                    throw ex;
                }
            }
            finally
            {
                TracePool.EnQueue(trace, output);
            }

            #endregion

            return(output);
        }
コード例 #3
0
        private static string BrokerDnsInner(Dictionary <string, string> input, Micro micro)
        {
            string output = string.Empty;

            #region 调用链

            var trace = TransmitTrace.SetTraceId(input, micro);

            #endregion
            #region 处理请求
            try
            {
                using (Request request = new Request(micro.Ip, micro.Port))
                {
                    output = request.Invoke(input);
                }
            }
            catch (ThriftException ex)
            {
                if (ex.Type.Equals(ExceptionType.NotFoundService))
                {
                    _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                }
                output = FailMessage(ex.Message);
            }
            catch (Exception ex) //如果异常则从缓存中清除 该缓存
            {
                _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                output = FailMessage(ex.Message);
            }
            finally
            {
                TracePool.EnQueue(trace, output);
            }

            #endregion

            return(output);
        }
コード例 #4
0
        private static string BrokerDnsInner(Dictionary <string, string> input, Micro micro)
        {
            if (micro == null)
            {
                return(FailMessage($"未找到服务【{input[Eng.NAMESPACE]}】"));
            }
            string output = string.Empty;

            #region 调用链

            var trace = TransmitTrace.SetTraceId(input, micro);

            #endregion
            #region 处理请求
            int error = 0;
tryRequest:
            if (error > 0)
            {
                micro = Single(input[Eng.NAMESPACE])?.Mi;
                if (micro == null)
                {
                    return(FailMessage($"未找到服务【{input[Eng.NAMESPACE]}】"));
                }
            }
            try
            {
                using (Request request = new Request(micro.Ip, micro.Port))
                {
                    output = request.Invoke(input);
                }
            }
            catch (ThriftException ex)
            {
                if (ex.Type.Equals(ExceptionType.NotFoundService))
                {
                    _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                }
                output = FailMessage(ex.Message);
                error++;
                if (error < 3)
                {
                    goto tryRequest;
                }
            }
            catch (Exception ex) //如果异常则从缓存中清除 该缓存
            {
                _microCaches.RemoveAll(c => c.Mi.Ip == micro.Ip && c.Mi.Port == micro.Port);
                output = FailMessage(ex.Message);
                error++;
                if (error < 3)
                {
                    goto tryRequest;
                }
            }
            finally
            {
                TracePool.EnQueue(trace, output);
            }

            #endregion

            return(output);
        }