Can both ends of the gRPC connection method call?

From the introduction to gRPC :

In gRPC, a client application can directly call server application methods on another computer, as if it were a local object, which simplifies the creation of distributed applications and services. As with many RPC systems, gRPC is based on the idea of ​​defining a service, defining methods that can be called remotely, with their parameters and return types. On the server side, the server implements this interface and starts the gRPC server to process client calls. On the client side, the client has a stub that provides the same methods as the server.

The paragraph above refers to the client and server, with the first invoking methods to the other. What interests me is: can the server side of the connection call methods that have been registered on the client?

+9
source share
3 answers

No, the server cannot make calls on the client. gRPC works with HTTP, and HTTP did not have such semantics in the past.

Various ways to achieve this have been discussed, but I don’t know about any work or general design agreement. gRPC supports bidirectional streaming, which can help you with what you need. In bidirectional streaming, the client can respond to messages from the server, but the client still calls the server, and only one type of message can be sent for this call.

+13

, HTTP- . , ( , ), .

+2

, , .

, ServerRequest:


import "google/protobuf/any.proto";

service FullDuplex {
    rpc WaitRequests (google.protobuf.Any) returns (stream ServerRequest);
}

message ServerRequest {
    float someValue = 1;

    float anotherAnother = 1;
}

ServerRequest Oneof, .

, , , , - .

service FullDuplex {
    rpc WaitRequests (stream ClientResponse) returns (stream ServerRequest);
}

0

All Articles