Skip to content

evsinev/grpc-java-long-polling

Repository files navigation

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();

About

gRPC long polling implementation

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages