可以通过 RpcContext 的 setAttachment() 和 getAttachment() 在Consumer和Provider之间进行参数的隐式传递,例如Controller层拦截登录token,把根据token得到的memberId传给dubbo服务就能使用隐式参数传递的方式,setAttachment()设置的 KV 对,在完成一次远程调用会被清空,即多次远程调用要多次设置。使用方式:
1.服务端set:
RpcContext.getContext().setAttachment(“CRT_MEMBER_ID”, “13828886888”);
2.客户端get:
RpcContext.getContext().getAttachment(“CRT_MEMBER_ID”)