Beispiel #1
0
        public virtual async Task ReceiveAsync(IRpcContext <AmpMessage> context, AmpMessage message)
        {
            using (var audit = new RequestAuditLogger())
            {
                AmpMessage rsp;
                try
                {
                    audit.PushRequest(message);
                    Logger.LogDebug("recieve message,Id={0}", message.Id);
                    rsp = await ProcessAsync(message);

                    rsp.Sequence = message.Sequence; //通讯请求序列

                    audit.PushResponse(rsp);
                    audit.PushContext(context);

                    await context.SendAsync(rsp);

                    //Logger.LogError("send message,Id={0}", message.Id);
                }
                catch (ClosedChannelException closedEx)
                {
                    Logger.LogError(closedEx, "recieve message occ error,channel closed,{messageId}", message.Id);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "recieve message occ error");
                    rsp = await SendErrorResponseAsync(context, message);

                    audit.PushResponse(rsp);
                }
            }
        }
        protected Task ReceiveNotFoundAsync(IRpcContext <AmpMessage> context, AmpMessage req)
        {
            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.Sequence          = req.Sequence;
            response.InvokeMessageType = DotBPE.Rpc.Codes.InvokeMessageType.NotFound;
            Logger.Error("recieve message serviceId={0},messageId={1},Length ={2},Actor NotFound", req.ServiceId, req.MessageId, req.Length);
            return(context.SendAsync(response));
        }
Beispiel #3
0
//调用委托
        private async Task ReceiveHelloAsync(IRpcContext <AmpMessage> context, AmpMessage req)
        {
            var request = HelloRequest.Parser.ParseFrom(req.Data);
            var data    = await HelloAsync(request);

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

            response.Sequence = req.Sequence;
            response.Data     = data.ToByteArray();
            await context.SendAsync(response);
        }
        public async Task ReceiveAsync(IRpcContext <AmpMessage> context, AmpMessage message)
        {
            AmpMessage response = new AmpMessage
            {
                InvokeMessageType = InvokeMessageType.NotFound,
                ServiceId         = message.ServiceId,
                MessageId         = message.MessageId
            };

            response.Sequence = message.Sequence;
            await context.SendAsync(response);
        }
Beispiel #5
0
        public async Task ReceiveAsync(IRpcContext <AmpMessage> context, AmpMessage message)
        {
            AmpMessage response = new AmpMessage
            {
                InvokeMessageType = InvokeMessageType.Response,
                Code      = ErrorCodes.CODE_SERVICE_NOT_FOUND,
                ServiceId = message.ServiceId,
                MessageId = message.MessageId
            };

            response.Sequence = message.Sequence;
            await context.SendAsync(response);
        }
Beispiel #6
0
 /// <summary>
 /// 发送服务端意外错误的消息
 /// </summary>
 /// <param name="context"></param>
 /// <param name="reqMessage"></param>
 /// <returns></returns>
 private Task SendErrorResponseTask(IRpcContext <AmpMessage> context, AmpMessage reqMessage)
 {
     try
     {
         var rsp = AmpMessage.CreateResponseMessage(reqMessage.ServiceId, reqMessage.MessageId);
         rsp.InvokeMessageType = InvokeMessageType.ERROR;
         rsp.Sequence          = reqMessage.Sequence;
         return(context.SendAsync(rsp));
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "send error response fail:" + ex.Message);
         return(Rpc.Utils.TaskUtils.CompletedTask);
     }
 }
Beispiel #7
0
        public virtual async Task ReceiveAsync(IRpcContext <AmpMessage> context, AmpMessage message)
        {
            try
            {
                var response = await ProcessAsync(message);

                response.Sequence = message.Sequence; //通讯请求序列
                await context.SendAsync(response);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "recieve message occ error:" + ex.Message);
                await SendErrorResponseAsync(context, message);
            }
        }
Beispiel #8
0
        /// <summary>
        /// 发送服务端意外错误的消息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="reqMessage"></param>
        /// <returns></returns>
        private async Task <AmpMessage> SendErrorResponseAsync(IRpcContext <AmpMessage> context, AmpMessage reqMessage)
        {
            var rsp = AmpMessage.CreateResponseMessage(reqMessage.ServiceId, reqMessage.MessageId);

            rsp.InvokeMessageType = InvokeMessageType.Response;
            rsp.Sequence          = reqMessage.Sequence;
            rsp.Code = ErrorCodes.CODE_INTERNAL_ERROR; //内部错误
            try
            {
                await context.SendAsync(rsp);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "send error response fail:" + ex.Message);
            }

            return(rsp);
        }
Beispiel #9
0
 public Task ReceiveAsync(IRpcContext <TMessage> context, TMessage message)
 {
     message.InvokeMessageType = InvokeMessageType.Response;
     return(context.SendAsync(message));
 }