The dubbo generalization call causes the number of the same consumer node in zk to increase

dubbo2.6.8 generalization call causes the number of the same consumer node in zk to increase

During the generalization call, if you check whether the service exists, an exception will be thrown if the service does not exist, but the consumer node has been created before, so as long as a large number of generalization calls this non-existent service, it will cause the consumer node on ZK to become more More and more, causing performance problems for ZK
Insert picture description here
com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry#doRegister
Insert picture description here

com.alibaba.dubbo.config.ReferenceConfig
Insert picture description here

Test code

@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";
    }
}

Guess you like

Origin blog.csdn.net/u013202238/article/details/108869362