Skip to content

A dynamic grpc client does not rely on the generated code, the input and output are all in JSON format, and the proto file is modified dynamically

License

Notifications You must be signed in to change notification settings

dengzhicheng/grpc-dynamic-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grpc-dynamic-client

A dynamic grpc client does not rely on the generated code, the input and output are all in JSON format, and the proto file is modified dynamically

Features

  • Do not rely on the generated code.
  • Support dynamic registration and modification of clients.
  • Support grpc client simple connection pool.

Usage

    String name = "xxx-grpc";
    File file = new File(Example.class.getClass().getResource("/example.proto").getPath());
    String protoFileContent = Resources.toString(file.toURI().toURL(), Charsets.UTF_8);
    // # address examples
    // # 10.0.0.10:9090
    // # dns:/example.com
    String address = "127.0.0.1:8888";
    int connections = 5;
    // registerClient
    GrpcClientConfig clientCfg = GrpcClientConfig.custom().name(name).protoFileContent(protoFileContent).address(address).connections(connections).build();
    DynamicGrpcClients.registerClient(clientCfg);
    String api = "ExampleServer/info";
    String paramsJson = "{\"name\":\"abc\",\"title\":\"abcd\"}";
    int timeout = 5000;
    DynamicGrpcClients client = DynamicGrpcClients.custom().name(name).api(api).paramsJson(paramsJson).timeout(timeout).build();
    GrpcResponse response = client.execute();
    System.out.println(response);

About

A dynamic grpc client does not rely on the generated code, the input and output are all in JSON format, and the proto file is modified dynamically

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages