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

metainfo传值问题 #412

Closed
971181317 opened this issue Apr 18, 2022 · 1 comment
Closed

metainfo传值问题 #412

971181317 opened this issue Apr 18, 2022 · 1 comment

Comments

@971181317
Copy link

client中使用了如下的代码

// gin mw
func InitReq(c *gin.Context) {
	...
	rpcctx := metainfo.WithPersistentValue(context.Background(), "logid", logid)
	c.Set("rpcctx", rpcctx)
	...
}
func GetRpcCtx(c *gin.Context) context.Context {
	res, _ := c.Get("rpcctx")
	return res.(context.Context)
}
func RpcTestHandler(c *gin.Context) {
        ...... 
	c1 := GetRpcCtx(c)
        fmt.Println(metainfo.GetPersistentValue(c1, "logid")) // 可以获取到存入的值
	resp, err := rpc.XXXX.Pingpong(c1, xxx.NewPingPongRequest())
	.....
}

rpc server mw代码,中间件无法获取到上游gin服务中的PersistentValue

func ImportLinkMW(next endpoint.Endpoint) endpoint.Endpoint {
	return func(ctx context.Context, request, response interface{}) error {
                // ok: false
		logid, ok := metainfo.GetPersistentValue(ctx, "logid")
		fmt.Println(metainfo.GetPersistentValue(ctx, "logid"))
		if !ok || logid == "" {
			ctx = metainfo.WithPersistentValue(ctx, "logid", "12345")
		}
		fmt.Println(logid)
		err := next(ctx, request, response)
		return err
	}
}

编码使用thrift,传输协议未修改,请问一下数据没有传到下游是因为context的问题还是有什么其他的配置,

@lsjbd
Copy link
Contributor

lsjbd commented Apr 18, 2022

编码使用thrift,传输协议未修改,请问一下数据没有传到下游是因为context的问题还是有什么其他的配置,

客户端默认的协议不支持传递元信息。你需要增加一个 option:

client.WithTransportProtocol(transport.TTHeaderFramed),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants