in protocol/dubbo3/dubbo3_invoker.go [157:234]
func (di *DubboInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
var (
result protocol.RPCResult
)
if !di.BaseInvoker.IsAvailable() {
// Generally, the case will not happen, because the invoker has been removed
// from the invoker list before destroy,so no new request will enter the destroyed invoker
logger.Warnf("this dubboInvoker is destroyed")
result.Err = protocol.ErrDestroyedInvoker
return &result
}
di.clientGuard.RLock()
defer di.clientGuard.RUnlock()
if di.client == nil {
result.Err = protocol.ErrClientClosed
return &result
}
if !di.BaseInvoker.IsAvailable() {
// Generally, the case will not happen, because the invoker has been removed
// from the invoker list before destroy,so no new request will enter the destroyed invoker
logger.Warnf("this grpcInvoker is destroying")
result.Err = protocol.ErrDestroyedInvoker
return &result
}
for _, k := range attachmentKey {
var paramKey string
switch k {
case tripleConstant.TripleServiceGroup:
paramKey = constant.GroupKey
case tripleConstant.TripleServiceVersion:
paramKey = constant.VersionKey
default:
paramKey = k
}
if v := di.GetURL().GetParam(paramKey, ""); len(v) > 0 {
invocation.SetAttachment(k, v)
}
}
// append interface id to ctx
gRPCMD := make(metadata.MD, 0)
// triple will convert attachment value to []string
for k, v := range invocation.Attachments() {
if str, ok := v.(string); ok {
gRPCMD.Set(k, str)
continue
}
if str, ok := v.([]string); ok {
gRPCMD.Set(k, str...)
continue
}
logger.Warnf("[Triple Protocol]Triple attachment value with key = %s is invalid, which should be string or []string", k)
}
ctx = metadata.NewOutgoingContext(ctx, gRPCMD)
ctx = context.WithValue(ctx, tripleConstant.InterfaceKey, di.BaseInvoker.GetURL().GetParam(constant.InterfaceKey, ""))
in := make([]reflect.Value, 0, 16)
in = append(in, reflect.ValueOf(ctx))
if len(invocation.ParameterValues()) > 0 {
in = append(in, invocation.ParameterValues()...)
}
methodName := invocation.MethodName()
triAttachmentWithErr := di.client.Invoke(methodName, in, invocation.Reply())
result.Err = triAttachmentWithErr.GetError()
result.Attrs = make(map[string]any)
for k, v := range triAttachmentWithErr.GetAttachments() {
result.Attrs[k] = v
}
result.Rest = invocation.Reply()
return &result
}