Beispiel #1
0
        //调用委托
        private async Task <AmpMessage> ProcessSayHelloAgainAsync(AmpMessage req)
        {
            HelloReq request = null;

            if (req.Data == null)
            {
                request = new HelloReq();
            }
            else
            {
                request = HelloReq.Parser.ParseFrom(req.Data);
            }

            req.FriendlyServiceName = "Greeter.SayHelloAgain";

            var result = await SayHelloAgainAsync(request);

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

            response.FriendlyServiceName = "Greeter.SayHelloAgain";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
        //同步方法
        public RpcResult <HelloRes> SayHelloAgain(HelloReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

            message.FriendlyServiceName = "Greeter.SayHelloAgain";


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

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <HelloRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = HelloRes.Parser.ParseFrom(response.Data);
            }
            return(result);
        }
        public async Task <RpcResult <HelloRes> > SayHelloAsync(HelloReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 1);

            message.FriendlyServiceName = "Greeter.SayHello";
            message.Data = req.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            var result = new RpcResult <HelloRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = HelloRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Beispiel #4
0
        public override Task <HelloRes> SayHelloAgainAsync(HelloReq request)
        {
            var res = new HelloRes()
            {
                GreetWord = $"Hello {request.Name} Again!"
            };

            return(Task.FromResult(res));
        }
        public override Task <RpcResult <HelloRes> > SayHelloAsync(HelloReq request)
        {
            var res = new RpcResult <HelloRes>();

            res.Data = new HelloRes()
            {
                GreetWord = $"Hello {request.Name} !"
            };
            return(Task.FromResult(res));
        }
Beispiel #6
0
//同步方法
        public HelloRes SayHelloAgain(HelloReq request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

            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 HelloRes());
            }
            return(HelloRes.Parser.ParseFrom(response.Data));
        }
Beispiel #7
0
        public async Task <HelloRes> SayHelloAgainAsync(HelloReq request, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(10006, 2);

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

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new HelloRes());
            }
            return(HelloRes.Parser.ParseFrom(response.Data));
        }
Beispiel #8
0
//调用委托
        private async Task <AmpMessage> ProcessSayHelloAgainAsync(AmpMessage req)
        {
            HelloReq request = null;

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

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

            response.Data = data.ToByteArray();
            return(response);
        }
Beispiel #9
0
 //抽象方法
 public abstract Task <RpcResult <HelloRes> > SayHelloAgainAsync(HelloReq req);
Beispiel #10
0
//抽象方法
        public abstract Task <HelloRes> SayHelloAgainAsync(HelloReq request);