Пример #1
0
        //同步方法
        public RpcResult <VoidRes> Schedule(ScheduleReq req)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(1000, 2);

            message.FriendlyServiceName = "TaskProducerService.Schedule";


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

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

            if (response.Code != 0)
            {
                result.Code = response.Code;
            }
            else if (response.Data == null)
            {
                result.Code = ErrorCodes.CODE_INTERNAL_ERROR;
            }
            else
            {
                result.Data = VoidRes.Parser.ParseFrom(response.Data);
            }
            return(result);
        }
Пример #2
0
        public async Task <RpcResult <VoidRes> > ScheduleSecondAsync(ScheduleReq req, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(1000, 3);

            message.FriendlyServiceName = "TaskProducerService.ScheduleSecond";
            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 <VoidRes>();

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

            return(result);
        }
        //调用委托
        private async Task <AmpMessage> ProcessScheduleAsync(AmpMessage req)
        {
            ScheduleReq request = null;

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

            req.FriendlyServiceName = "TaskProducerService.Schedule";

            var result = await ScheduleAsync(request);

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

            response.FriendlyServiceName = "TaskProducerService.Schedule";
            response.Code = result.Code;
            if (result.Data != null)
            {
                response.Data = result.Data.ToByteArray();
            }
            return(response);
        }
 //抽象方法
 public abstract Task <RpcResult <VoidRes> > ScheduleAsync(ScheduleReq req);