示例#1
0
        private void BatchDequeueProc(KeyWrapper <ServerUri, RpcConnection> key, RpcBatchClientTransaction[] txs)
        {
            RpcBatchRequest[] requests = new RpcBatchRequest[txs.Length];

            for (int i = 0; i < txs.Length; i++)
            {
                requests[i] = txs[i].BatchRequest;
            }

            RpcRequest request = new RpcRequest(txs[0].Request.Service, txs[0].Request.Method, null);

            request.BodyBuffer = new RpcBodyBuffer <RpcBatchRequest[]>(requests);

            if (key.Token == null)
            {
                lock (_syncRoot) {
                    key.Token = RpcProxyFactory.GetConnection(key.Key, txs[0].ServiceRole);
                }
            }

            RpcClientTransaction trans = key.Token.CreateTransaction(request);
            RpcClientContext     ctx   = new RpcClientContext(trans);

            ctx.SendRequest(
                delegate(long elapseTicks, RpcClientContext c2, bool successed) {
                try {
                    RpcBatchResponse[] resps = ctx.EndInvoke <RpcBatchResponse[]>();
                    if (resps.Length != txs.Length)
                    {
                        ProcessFailedTxs(txs, RpcErrorCode.InvaildResponseArgs, new Exception("Batch Length NotMatch"));
                    }
                    else
                    {
                        for (int i = 0; i < resps.Length; i++)
                        {
                            txs[i].BatchResponse = resps[i];
                            txs[i].OnTransactionEnd();
                        }
                    }
                } catch (RpcException ex) {
                    ProcessFailedTxs(txs, ex.RpcCode, ex.InnerException);
                } catch (Exception ex) {
                    ProcessFailedTxs(txs, RpcErrorCode.ServerError, ex);
                }
            },
                -1
                );
        }
示例#2
0
 /// <summary>
 /// SGW专用,其他慎用
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="request"></param>
 /// <param name="manager"></param>
 public RpcBatchClientTransaction(ServerUri uri, RpcBatchRequest request, RpcClientBatchManager manager)
     : base(uri, null)
 {
     _manager      = manager;
     _batchRequest = request;
 }