Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix - triple protocol request doesn't carry attachment such as group or version. #1700

Merged
merged 8 commits into from
Jan 7, 2022
12 changes: 12 additions & 0 deletions protocol/dubbo3/dubbo3_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ import (
invocation_impl "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)

// same as dubbo_invoker.go attachmentKey
var attachmentKey = []string{
constant.InterfaceKey, constant.GroupKey, constant.TokenKey, constant.TimeoutKey,
constant.VersionKey,
}

// DubboInvoker is implement of protocol.Invoker, a dubboInvoker refer to one service and ip.
type DubboInvoker struct {
protocol.BaseInvoker
Expand Down Expand Up @@ -166,6 +172,12 @@ func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
return &result
}

for _, k := range attachmentKey {
if v := di.GetURL().GetParam(k, ""); len(v) > 0 {
invocation.SetAttachments(k, v)
}
}

// append interface id to ctx
gRPCMD := make(metadata.MD, 0)
for k, v := range invocation.Attachments() {
Expand Down
10 changes: 8 additions & 2 deletions protocol/dubbo3/dubbo3_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

import (
"github.com/dubbogo/grpc-go"
"github.com/dubbogo/grpc-go/metadata"

tripleCommon "github.com/dubbogo/triple/pkg/common"
tripleConstant "github.com/dubbogo/triple/pkg/common/constant"
triConfig "github.com/dubbogo/triple/pkg/config"
"github.com/dubbogo/triple/pkg/triple"
Expand Down Expand Up @@ -194,7 +194,13 @@ func (d *UnaryService) GetReqParamsInterfaces(methodName string) ([]interface{},
}

func (d *UnaryService) InvokeWithArgs(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error) {
dubboAttachment, _ := ctx.Value(tripleConstant.TripleAttachement).(tripleCommon.DubboAttachment)
dubboAttachment := make(map[string]interface{})
md, ok := metadata.FromIncomingContext(ctx)
if ok {
for k := range md {
dubboAttachment[k] = md.Get(k)[0]
}
}
res := d.proxyImpl.Invoke(ctx, invocation.NewRPCInvocation(methodName, arguments, dubboAttachment))
return res, res.Error()
}
Expand Down