可以通过 RpcContext 上的 setAttachment 和 getAttachment 在服务消费方和提供方之间进行参数的隐式传递。

隐式参数 RpcContext

 

在服务消费方端设置隐式参数

setAttachment 设置的 KV 对,在完成下面一次远程调用会被清空,即多次远程调用要多次设置。

RpcContext.getContext().setAttachment("index", "1"); // 隐式传参,后面的远程调用都会隐式将这些参数发送到服务器端,类似cookie,用于框架集成,不建议常规业务使用
xxxService.xxx(); // 远程调用
// ...

在服务提供方端获取隐式参数

public class XxxServiceImpl implements XxxService {
    public void xxx() {
        // 获取客户端隐式传入的参数,用于框架集成,不建议常规业务使用
        String index = RpcContext.getContext().getAttachment("index"); 
    }
}

 

相关文章:

  • 2021-09-09
  • 2022-12-23
  • 2022-01-01
  • 2021-11-24
  • 2021-12-30
  • 2022-12-23
  • 2023-04-03
猜你喜欢
  • 2022-12-23
  • 2021-07-30
  • 2021-11-16
  • 2021-05-20
  • 2021-09-14
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案