Raising a server error to the client with grpc

Yes, there is a better way. You may change the status details using the ServicerContext.set_details method and you may change the status code using the ServicerContext.set_code method. I suspect that your servicer will look something like class MyService(proto_pb2.SomethingServicer): def Do(self, request, context): if not is_valid_field(request.field): context.set_code(grpc.StatusCode.INVALID_ARGUMENT) context.set_details(‘Consarnit!’) return proto_pb2.Response() return proto_pb2.Response(response=”Yeah!”) .

Why do I get this GRPC Error “WARNING: EmulatorService.cpp:448: Cannot find certfile” when I start the emulator?

Invalidate and Restart option in Android Studio, followed by gradle clean, and manually uninstalling the application from the emulator finally worked for me. Individually, they didn’t for whatever reason. I tried several other options mentioned without any luck. The file it mentioned “emulator-grpc.cer” still doesnt exist anywhere. There is a keystore in that folder called … Read more

gRPC + Image Upload

For large binary transfers, the standard approach is chunking. Chunking can serve two purposes: reduce the maximum amount of memory required to process each message provide a boundary for recovering partial uploads. For your use-case #2 probably isn’t very necessary. In gRPC, a client-streaming call allows for fairly natural chunking since it has flow control, … Read more

Is “google/protobuf/struct.proto” the best way to send dynamic JSON over GRPC?

Based on this proto file. syntax = “proto3”; package messages; import “google/protobuf/struct.proto”; service UserService { rpc SendJson (SendJsonRequest) returns (SendJsonResponse) {} } message SendJsonRequest { string UserID = 1; google.protobuf.Struct Details = 2; } message SendJsonResponse { string Response = 1; } I think it is a good solution to use the google.protobuf.Struct type. The … Read more

Protocol Buffer imports not recognized in Intellij

Take a look at the readme which describes how to add additional paths. By default, intellij-protobuf-editor uses the project’s configured source roots as protobuf import paths. If this isn’t correct, you can override these paths in Settings > Languages & Frameworks > Protocol Buffers. Uncheck “Configure automatically” and add whichever paths you need. In your … Read more

does grpc service must have exactly one input parameter and one return value

gRPC service methods have exactly one input message and exactly one output message. Typically, these messages are used as input and output to only one method. This is on purpose, as it allows easily adding new parameters later (to the messages) while maintaining backward compatibility. If you don’t want any input or output parameters, you … Read more

How to add global exception interceptor in gRPC server?

Below code will catch all runtime exceptions, Also refer the link https://github.com/grpc/grpc-java/issues/1552 public class GlobalGrpcExceptionHandler implements ServerInterceptor { @Override public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata requestHeaders, ServerCallHandler<ReqT, RespT> next) { ServerCall.Listener<ReqT> delegate = next.startCall(call, requestHeaders); return new SimpleForwardingServerCallListener<ReqT>(delegate) { @Override public void onHalfClose() { try { super.onHalfClose(); } catch (Exception e) { call.close(Status.INTERNAL … Read more

File not found.