program tip

null 요청 또는 응답으로 grpc 호출을 정의 할 수 있습니까?

radiobox 2020. 9. 8. 07:49
반응형

null 요청 또는 응답으로 grpc 호출을 정의 할 수 있습니까?


proto3의 rpc 구문이 null 요청 또는 응답을 허용합니까?

예를 들어 다음과 같은 것을 원합니다.

rpc Logout;
rpc Status returns (Status);
rpc Log (LogData);

아니면 그냥 null 유형을 만들어야합니까?

message Null {};

rpc Logout (Null) returns (Null);
rpc Status (Null) returns (Status);
rpc Log (LogData) returns (Null);

아래 Kenton의 의견은 건전한 조언입니다.

... 개발자로서 우리는 미래에 우리가 원하는 것이 무엇인지 추측하는 데 정말 나쁩니다. 따라서 비어있는 경우에도 모든 메서드에 대해 항상 사용자 지정 매개 변수와 결과 유형을 정의하여 안전 할 것을 권장합니다.


내 질문에 답하기 :

기본 proto 파일을 살펴보면 위에서 제안한 Null 유형과 똑같은 Empty를 발견 했습니다. :)

해당 파일에서 발췌 :

// A generic empty message that you can re-use to avoid defining duplicated
// empty messages in your APIs. A typical example is to use it as the request
// or the response type of an API method. For instance:
//
//     service Foo {
//       rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
//     }
//

message Empty {

}

참고 URL : https://stackoverflow.com/questions/31768665/can-i-define-a-grpc-call-with-a-null-request-or-response

반응형