- Dubbo version: 3.1.5
- Java version: 1.8
1.成功调用到提供端,但是返回异常,返回报: [DUBBO] Decode rpc invocation failed: null, dubbo version: 3.1.5, current host: 192.168.0.190, error code: 4-20. This may be caused by , go to https://dubbo.apache.org/faq/4/20 to find instructions.
java.lang.NullPointerException: null at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at org.apache.dubbo.rpc.support.GroupServiceKeyCache.getServiceKey(GroupServiceKeyCache.java:37) at org.apache.dubbo.rpc.support.ProtocolUtils.serviceKey(ProtocolUtils.java:51) at org.apache.dubbo.rpc.protocol.AbstractProtocol.serviceKey(AbstractProtocol.java:83) at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.getInvoker(DubboProtocol.java:282)
2.使用的是dubbo 3.1.5 3.通过日志发现消费端会3次进入invoke方法,这个过滤器主要用来设置额外请求参数
过滤器代码如下: `@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, order = -1) public class DubboTenantFilter implements Filter { protected final Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
//判断是消费者 还是 服务提供者
System.out.println("invoke:"+RpcContext.getContext().isConsumerSide());
if (RpcContext.getContext().isConsumerSide()) {
//消费者 将tenant_id set至上下文中
RpcContext.getContext().setAttachment(DefConstants.TENANT_HEADER_KEY, TenantContextHolder.getTenantId());
} else {
String tenantId = RpcContext.getContext().getAttachment(DefConstants.TENANT_HEADER_KEY);
if(tenantId!=null){
TenantContextHolder.setTenantId(tenantId);
}
}
try {
return invoker.invoke(invocation);
}finally {
if (RpcContext.getContext().isProviderSide()) {
TenantContextHolder.clear();
}
}
}
}`