You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a service that needs to use grpc proxy, so I implemented a custom one based on this repo. It works well as I use grpc.NewServer(grpc.CustomCodec(proxy.Codec()), ...) to receive the requests from client and then send them to the server with grpc.DialContext(ctx, target, grpc.WithCodec(proxy.Codec()), grpc.WithInsecure()), where proxy.Codec() is a custom Codec that "basically treats a gRPC message frame as raw bytes, however, if the server handler, or the client caller are not proxy-internal functions it will fall back to trying to decode the message using a fallback codec."
Then I found that grpc.Codec, grpc.WithCodec(), grpc.CustomCodec() had been deprecated and it's recommended to use encoding.RegisterCodec() to register codecs. I replaced them, however the client then reported an error failed to unmarshal, message is *proxy.frame, want proto.Message. After reading the encoding.md, I realized the problem was that my client used the default "proto" Codec, so the proxy will automatically chose using the "proto" codec instead of proxy.Codec() that I've registered. To deal with this, I have to add grpc.WithDefaultCallOptions(grpc.CallContentSubtype("MyCodec")) as the client 's dial option, which deviated from intention of using a user-unaware proxy.
Is there any method to force using a certain encoding.Codec for only one end like previously we used grpc.CustomCodec() and grpc.WithCodec()?
The text was updated successfully, but these errors were encountered:
We have a service that needs to use grpc proxy, so I implemented a custom one based on this repo. It works well as I use
grpc.NewServer(grpc.CustomCodec(proxy.Codec()), ...)
to receive the requests from client and then send them to the server withgrpc.DialContext(ctx, target, grpc.WithCodec(proxy.Codec()), grpc.WithInsecure())
, whereproxy.Codec()
is a custom Codec that "basically treats a gRPC message frame as raw bytes, however, if the server handler, or the client caller are not proxy-internal functions it will fall back to trying to decode the message using a fallback codec."Then I found that
grpc.Codec, grpc.WithCodec(), grpc.CustomCodec()
had been deprecated and it's recommended to useencoding.RegisterCodec()
to register codecs. I replaced them, however the client then reported an errorfailed to unmarshal, message is *proxy.frame, want proto.Message
. After reading the encoding.md, I realized the problem was that my client used the default "proto" Codec, so the proxy will automatically chose using the "proto" codec instead ofproxy.Codec()
that I've registered. To deal with this, I have to addgrpc.WithDefaultCallOptions(grpc.CallContentSubtype("MyCodec"))
as the client 's dial option, which deviated from intention of using a user-unaware proxy.Is there any method to force using a certain
encoding.Codec
for only one end like previously we usedgrpc.CustomCodec()
andgrpc.WithCodec()
?The text was updated successfully, but these errors were encountered: