Skip to content
Snippets Groups Projects
Commit dea5d83f authored by pantianying's avatar pantianying
Browse files

provider can get attachment in ctx

parent f1d03e95
No related branches found
No related tags found
No related merge requests found
......@@ -180,6 +180,9 @@ const (
// ForceUseTag is the tag in attachment
ForceUseTag = "dubbo.force.tag"
Tagkey = "dubbo.tag"
// Attachment key in context in invoker
AttachmentKey = "attachment"
)
const (
......
......@@ -25,6 +25,7 @@ import (
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
invocation_impl "github.com/apache/dubbo-go/protocol/invocation"
......@@ -140,7 +141,7 @@ func (p *Proxy) Implement(v common.RPCService) {
}
// add user setAttachment
atm := invCtx.Value("attachment")
atm := invCtx.Value(constant.AttachmentKey)
if m, ok := atm.(map[string]string); ok {
for k, value := range m {
inv.SetAttachments(k, value)
......@@ -148,6 +149,10 @@ func (p *Proxy) Implement(v common.RPCService) {
}
result := p.invoke.Invoke(invCtx, inv)
logger.Error(result.Attachments())
if len(result.Attachments()) > 0 {
invCtx = context.WithValue(invCtx, constant.AttachmentKey, result.Attachments())
}
err = result.Error()
logger.Debugf("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err)
......
......@@ -113,6 +113,7 @@ func (pi *ProxyInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
in := []reflect.Value{svc.Rcvr()}
if method.CtxType() != nil {
ctx = context.WithValue(ctx, constant.AttachmentKey, invocation.Attachments())
in = append(in, method.SuiteContext(ctx))
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment