Search code examples
grpc

How can I make server query some data from client via grpc?


I am using grpc for client/server communication since it supports bidirectional streaming. I have read some doc relates to that: https://grpc.io/docs/what-is-grpc/introduction/

It supports:

  • A simple RPC where the client request to server to receive a response

  • A server-side streaming RPC where the client sends a request to the server and gets a stream to read a sequence of messages back.

  • A client-side streaming RPC where the client writes a sequence of messages and sends them to the server, again using a provided stream

I have a case that to let server to send a query request to client to receive a response. The bi-directional is only used in streaming case not request-response case.

I couldn't find any way to support that pattern. Is this supported by grpc?


Solution

  • The initiator of a request is by definition the client.

    To address your need:

    1. the code currently functioning only as a gRPC server must also implement a gRPC client; and
    2. the code currently functioning only as a gRPC client must also implement a gRPC server.