Search in sources :

Example 1 with RpcFrameworkException

use of com.quancheng.saluki.core.grpc.exception.RpcFrameworkException in project tesla by linking12.

the class DynamicGrpcClient method doRemoteCall.

@Override
public String doRemoteCall(final FilterRpcDO rpcDo, final String jsonInput) {
    try {
        final String serviceName = rpcDo.getServiceName();
        final String methodName = rpcDo.getMethodName();
        final String group = rpcDo.getServiceGroup();
        final String version = rpcDo.getServiceVersion();
        Pair<Descriptor, Descriptor> inOutType = ProtobufUtil.resolveServiceInputOutputType(rpcDo);
        Descriptor inPutType = inOutType.getLeft();
        Descriptor outPutType = inOutType.getRight();
        MethodDescriptor<DynamicMessage, DynamicMessage> methodDesc = this.createGrpcMethodDescriptor(serviceName, methodName, inPutType, outPutType);
        DynamicMessage message = this.createGrpcDynamicMessage(inPutType, jsonInput);
        Message response = (Message) genricService.$invoke(serviceName, group, version, methodName, methodDesc, message);
        return JSON2PROTOBUF.printToString(response);
    } catch (IOException e) {
        throw new RpcServiceException(String.format("json covert to DynamicMessage failed! the json is :%s, the protobuf type is: %s", jsonInput), e);
    } catch (Throwable e) {
        throw new RpcFrameworkException(String.format("service definition is wrong,please check the proto file you update,service is %s, method is %s", rpcDo.getServiceName(), rpcDo.getMethodName()), e);
    }
}
Also used : RpcFrameworkException(com.quancheng.saluki.core.grpc.exception.RpcFrameworkException) DynamicMessage(com.google.protobuf.DynamicMessage) Message(com.google.protobuf.Message) Descriptor(com.google.protobuf.Descriptors.Descriptor) MethodDescriptor(io.grpc.MethodDescriptor) RpcServiceException(com.quancheng.saluki.core.grpc.exception.RpcServiceException) DynamicMessage(com.google.protobuf.DynamicMessage) IOException(java.io.IOException)

Aggregations

Descriptor (com.google.protobuf.Descriptors.Descriptor)1 DynamicMessage (com.google.protobuf.DynamicMessage)1 Message (com.google.protobuf.Message)1 RpcFrameworkException (com.quancheng.saluki.core.grpc.exception.RpcFrameworkException)1 RpcServiceException (com.quancheng.saluki.core.grpc.exception.RpcServiceException)1 MethodDescriptor (io.grpc.MethodDescriptor)1 IOException (java.io.IOException)1