dubbo-go-hessian2 icon indicating copy to clipboard operation
dubbo-go-hessian2 copied to clipboard

how to rewrite attachment

Open champly opened this issue 4 years ago • 3 comments

背景

service mesh环境下,需要在 sidecar 中解析dubboattachment,并根据需求添加一些自定义的参数进去,就像SetHeader一样,然后重新构建 dubbo

问题

如果使用hessian.NewDecoder,传递的参数没有对象是可以的,如果参数中有对象会报错,参考 #163 的解决办法,使用 hessian.NewDecoderWithSkip可以解决,但是重新构建的时候arg类型是interface{},值是nil

解决

能否多提供一个Decode方法,直接返回[]byte内容,重新构建的时候直接encode.Append(arg)就可以重新构建dubbo

champly avatar May 15 '20 07:05 champly

solve

decode

  1. use hessian.NewDecoderWithSkip Decode dubboVersion/path/version/method/argsTypes/args/attachment info.
  2. create hessian encode object, encode attachment.
  3. calc encode len

encode

  1. encode.Append(payload[len(payload]-attachment_encode_len)
  2. encode.Encode(attachment)

champly avatar May 21 '20 03:05 champly

hello folks ..! I am good at java and I wanted to resolve this issue so please explain this issue some more detail as this is my first contribution .

RAJASHEKARGUNAGANTI avatar Feb 03 '23 19:02 RAJASHEKARGUNAGANTI

some materials:

  • dubbo rpc protocol: https://cn.dubbo.apache.org/zh/blog/2018/10/05/dubbo-%e5%8d%8f%e8%ae%ae%e8%af%a6%e8%a7%a3/
  • dubbo rpc protocol implement : https://github.com/apache/dubbo-go/blob/master/protocol/dubbo/dubbo_protocol.go

dubbo rpc attachments belongs to the Variable Part, but u can't get where it starts from, u must skip the parts before it, include Dubbo version, Service name, Service version, Method name, Method parameter types, Method arguments. But for hessian2 serialization protocol , u must decode the data to find where it ends with. There is't a length to tell the length of the data. So it costs a lot for the sidecar of mesh to update the attachments.

And I'm not sure whether the MOSN has already implemented this feature.

tiltwind avatar Feb 05 '23 09:02 tiltwind