Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 2.48 KB

File metadata and controls

42 lines (30 loc) · 2.48 KB

gRPC long polling implementation

Build Status Maven Central codecov codebeat badge Codacy Badge Quality Gate Status

Many web servers (ex. nginx), load balancers do not yet support HTTP/2 upstream. This project implemented both gRPC server and client with long polling via HTTP/1.1

Client example

ManagedChannel channel = LongPollingChannelBuilder.forTarget("http://localhost:9096/test").build();
GreeterGrpc.GreeterBlockingStub service = GreeterGrpc
        .newBlockingStub(channel)
        .withDeadlineAfter(5, TimeUnit.SECONDS);

HelloRequest request = HelloRequest.newBuilder().setName("hello").build();
HelloReply reply = service.sayHello(request);

Server example

LongPollingServer pollingServer = new LongPollingServer();

Server grpcServer = LongPollingServerBuilder.forPort(-1)
        .longPollingServer(pollingServer)
        .addService(new GreeterImpl())
        .build();
grpcServer.start();

ServerListener serverListener = pollingServer.waitForServerListener();

HelloWorldServer server = new HelloWorldServer(9096, new LongPollingDispatcherServlet(serverListener));
server.start();