Understanding gRPC's mustEmbedUnimplemented Method*
In its most recent update, gRPC-go has introduced the mustEmbedUnimplemented* method to ensure forward compatibility in its servers. But what exactly does it do?
Prior to mustEmbedUnimplemented*
Previously, registering a server implementation involved registering it directly, as shown:
pb.RegisterFooBarServiceServer( server, &FooBarServer{}, // or whatever you use to construct the server impl )
If the server lacked certain method implementations, it would result in errors during compilation.
Introducing mustEmbedUnimplemented*
With the updated protoc-gen-grpc-go compiler, forward-compatibility becomes the default. This means:
Configuring Forward Compatibility
Additionally, forward compatibility can be disabled by setting the following option when using protoc-gen-grpc-go:
protoc --go-grpc_out=require_unimplemented_servers=false:.
Benefits
mustEmbedUnimplemented* ensures that servers are always forward compatible, preventing unexpected errors caused by unimplemented methods. By opting out with Unsafe FooBarServiceServer, developers can maintain backward compatibility while still adhering to the principles of forward compatibility.
The above is the detailed content of What is gRPC's `mustEmbedUnimplemented` Method and How Does it Ensure Forward Compatibility?. For more information, please follow other related articles on the PHP Chinese website!