mardi 8 août 2023

How to pass in "authority" field to gRPC stub?

I am trying to replicate a grpcurl request like the one below in Java code:
grpcurl .... -authority addr1 addr2:portnumber package.service/endpoint
How can I replicate a call like this using grpc stubs?

I created a channel to addr2 and created a stub like this, then I call the service I want to access:

ManagedChannel channel = ManagedChannelBuilder.forAddress("addr2", "portnumber")
        .useTransportSecurity()
        .build();

ServerReflectionGrpc.ServerReflectionStub reflectionStub = ServerReflectionGrpc
            .newStub(channel)
            .withCallCredentials(new MyCallCredentials())
...

reflectionStub.serverReflectionInfo(streamObserver)

However, this throws a grpc UNIMPLEMENTED error, I believe passing in the authority flag in this approach will solve the issue since it is currently not being directed to the right address. How can you do this? It seems like the CallOptions class has a "withAuthority" method, but I don't see a way to attach CallOptions directly to the stub itself.

I also am unable to create the channel directly to addr1; this brings about some different authentication issues. Any ideas are appreciated, thanks





Aucun commentaire:

Enregistrer un commentaire