Ejemplo n.º 1
0
        //调用委托
        private async Task <AmpMessage> ProcessExcuteAsync(AmpMessage req)
        {
            CommonTaskReq request = null;

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

            req.FriendlyServiceName = "TaskConsumerService.Excute";

            var result = await ExcuteAsync(request);

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

            response.FriendlyServiceName = "TaskConsumerService.Excute";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
        public async Task <RpcResult <TaskVoidRes> > ExcuteAsync(CommonTaskReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(2000, 100);

            message.FriendlyServiceName = "TaskConsumerService.Excute";
            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 <TaskVoidRes>();

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }

            if (response.Data == null)
            {
                result.Data = new TaskVoidRes();
            }
            else
            {
                result.Data = TaskVoidRes.Parser.ParseFrom(response.Data);
            }

            return(result);
        }
Ejemplo n.º 3
0
 //抽象方法
 public abstract Task <RpcResult <TaskVoidRes> > ExcuteAsync(CommonTaskReq req);