Ejemplo n.º 1
0
        private static BenchmarkMessage PrepareBenchmarkMessage()
        {
            var msg = new BenchmarkMessage();

            msg.Field1 = "REQUEST";
            msg.Field2 = 1;
            return(msg);
        }
Ejemplo n.º 2
0
        //同步方法
        public BenchmarkMessage Echo(BenchmarkMessage request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(50000, 1);

            message.Data = request.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response != null && response.Data != null)
            {
                return(BenchmarkMessage.Parser.ParseFrom(response.Data));
            }
            throw new RpcException("请求出错,请检查!");
        }
Ejemplo n.º 3
0
        public async Task <BenchmarkMessage> EchoAsync(BenchmarkMessage request, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(50000, 1);

            message.Data = request.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response != null && response.Data != null)
            {
                return(BenchmarkMessage.Parser.ParseFrom(response.Data));
            }
            throw new RpcException("请求出错,请检查!");
        }
Ejemplo n.º 4
0
//同步方法
        public BenchmarkMessage Echo(BenchmarkMessage request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(50000, 1);

            message.Data = request.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new BenchmarkMessage());
            }
            return(BenchmarkMessage.Parser.ParseFrom(response.Data));
        }
Ejemplo n.º 5
0
        //调用委托
        private async Task <AmpMessage> ProcessEchoAsync(AmpMessage req)
        {
            BenchmarkMessage request = null;

            if (req.Data == null)
            {
                request = new BenchmarkMessage();
            }
            else
            {
                request = BenchmarkMessage.Parser.ParseFrom(req.Data);
            }
            var data = await EchoAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.Sequence = req.Sequence;
            response.Data     = data.ToByteArray();
            return(response);
        }
Ejemplo n.º 6
0
 //抽象方法
 public abstract Task <BenchmarkMessage> EchoAsync(BenchmarkMessage request);
Ejemplo n.º 7
0
 public override Task <BenchmarkMessage> EchoAsync(BenchmarkMessage request)
 {
     request.Field1 = "OK";
     request.Field2 = 100;
     return(Task.FromResult(request));
 }