public RemotingResponse InvokeSync(RemotingRequest request, int timeoutMillis) { var task = InvokeAsync(request, timeoutMillis); var response = task.WaitResult(timeoutMillis + 1000); if (response == null) { if (!task.IsCompleted) { throw new RemotingTimeoutException(_serverEndPoint, request, timeoutMillis); } else if (task.IsFaulted) { throw new RemotingRequestException(_serverEndPoint, request, task.Exception); } else { throw new RemotingRequestException(_serverEndPoint, request, "Remoting response is null due to unkown exception."); } } return(response); }
public static byte[] BuildRequestMessage(RemotingRequest request) { byte[] IdBytes; byte[] IdLengthBytes; ByteUtil.EncodeString(request.Id, out IdLengthBytes, out IdBytes); var sequenceBytes = BitConverter.GetBytes(request.Sequence); var codeBytes = BitConverter.GetBytes(request.Code); var typeBytes = BitConverter.GetBytes(request.Type); var createdTimeBytes = ByteUtil.EncodeDateTime(request.CreatedTime); var headerBytes = HeaderUtil.EncodeHeader(request.Header); var headerLengthBytes = BitConverter.GetBytes(headerBytes.Length); return(ByteUtil.Combine( IdLengthBytes, IdBytes, sequenceBytes, codeBytes, typeBytes, createdTimeBytes, headerLengthBytes, headerBytes, request.Body)); }
/// <summary> /// 创建成功的输出对象 /// </summary> /// <param name="remotingRequest"></param> /// <param name="body"></param> /// <returns></returns> public static RemotingResponse CreateSuccessResponse(this RemotingRequest remotingRequest, byte[] body) { return(new RemotingResponse(remotingRequest.Type, remotingRequest.Code, remotingRequest.Sequence, remotingRequest.CreatedTime, ResponseState.Success, body, DateTime.Now, remotingRequest.Header, null)); }
/// <summary> /// 创建未找到方法的RemotingResponse /// </summary> /// <param name="remotingRequest"></param> /// <param name="methodName">方法名字</param> /// <returns></returns> public static RemotingResponse CreateNotFoundResponse(this RemotingRequest remotingRequest, string methodName) { string messag = $"Not Fount Method:[{methodName}]."; return(new RemotingResponse(remotingRequest.Type, remotingRequest.Code, remotingRequest.Sequence, remotingRequest.CreatedTime, ResponseState.NotFound, Encoding.UTF8.GetBytes(messag), DateTime.Now, remotingRequest.Header, null)); }
/// <summary> /// 创建处理出错的RemotingResponse /// </summary> /// <param name="remotingRequest"></param> /// <returns></returns> public static RemotingResponse CreateDealErrorResponse(this RemotingRequest remotingRequest) { return(new RemotingResponse(remotingRequest.Type, remotingRequest.Code, remotingRequest.Sequence, remotingRequest.CreatedTime, ResponseState.Error, DealErrorResponseBody, DateTime.Now, remotingRequest.Header, null)); }