dubbo泛化呼叫導致zk中同一個消費者節點數遞增

brucelwl發表於2020-10-06

dubbo2.6.8 泛化呼叫導致zk中同一個消費者節點數遞增
在這裡插入圖片描述
com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry#doRegister
在這裡插入圖片描述

com.alibaba.dubbo.config.ReferenceConfig
在這裡插入圖片描述

@Component
public class DubboGenericInvoker {

    @Autowired
    private ApplicationConfig application;

    @Autowired
    private RegistryConfig registry;

    public Object invoker(String id, String tag) {

        if (StringUtils.hasText(tag)) {
            RpcContext.getContext().setAttachment(Constants.TAG_KEY, tag);
        }

        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
        reference.setApplication(application);
        reference.setRegistry(registry);
        reference.setInterface("com.bruce.rpc.service.DubboService");
        reference.setGeneric(true); // 宣告為泛化介面

        //reference.setCheck(false);

        try {
            ReferenceConfigCache cache = ReferenceConfigCache.getCache();
            GenericService genericService = cache.get(reference);
            Object o = genericService.$invoke("finfById", new String[]{"java.lang.String"}, new Object[]{id});
            return o;

        } catch (Exception ex) {
            ex.printStackTrace();
            //reference.destroy();
        }
        return "aaa";
    }
}

相關文章