Java Code Examples for com.alibaba.dubbo.registry.Registry#register()

The following examples show how to use com.alibaba.dubbo.registry.Registry#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZookeeperRegistryTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
/*
  This UT is unstable, consider remove it later.
  @see https://github.com/apache/incubator-dubbo/issues/1787
 */
public void testStatusChecker() {
    RegistryStatusChecker registryStatusChecker = new RegistryStatusChecker();
    Status status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.UNKNOWN));

    Registry registry = zookeeperRegistryFactory.getRegistry(registryUrl);
    assertThat(registry, not(nullValue()));

    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.ERROR));

    registry.register(serviceUrl);
    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.OK));
}
 
Example 2
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
Example 3
Source File: RegistryProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
Example 4
Source File: RegistryProtocol.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
Example 5
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
Example 6
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
Example 7
Source File: Online.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public String execute(CommandContext commandContext, String[] args) {
    logger.info("receive online command");
    String servicePattern = ".*";
    if (args != null && args.length > 0) {
        servicePattern = args[0];
    }

    boolean hasService = false;

    List<ProviderModel> providerModelList = ApplicationModel.allProviderModels();
    for (ProviderModel providerModel : providerModelList) {
        if (providerModel.getServiceName().matches(servicePattern)) {
            hasService = true;
            Set<ProviderInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName());
            for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) {
                if (providerInvokerWrapper.isReg()) {
                    continue;
                }
                Registry registry = registryFactory.getRegistry(providerInvokerWrapper.getRegistryUrl());
                registry.register(providerInvokerWrapper.getProviderUrl());
                providerInvokerWrapper.setReg(true);
            }
        }
    }

    if (hasService) {
        return "OK";
    } else {
        return "service not found";
    }

}
 
Example 8
Source File: RegistryProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
        RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
        directory.setRegistry(registry);
        directory.setProtocol(protocol);
        // all attributes of REFER_KEY
        Map<String, String> parameters = new HashMap<String, String>(directory.getUrl().getParameters());
//        订阅的url consumer
//        consumer://192.168.43.108/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&check=false&default.client=netty4&dubbo=2.0.2&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=84351&qos.port=33333&side=consumer&timeout=3000000&timestamp=1570892444487
        URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters);
//        不是订阅所有接口
        if (!Constants.ANY_VALUE.equals(url.getServiceInterface())
                && url.getParameter(Constants.REGISTER_KEY, true)) {
//            注册订阅=》com.alibaba.dubbo.registry.support.FailbackRegistry.register()
            registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                    Constants.CHECK_KEY, String.valueOf(false)));
        }
//        订阅=》
        directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY,
                Constants.PROVIDERS_CATEGORY
                        + "," + Constants.CONFIGURATORS_CATEGORY
                        + "," + Constants.ROUTERS_CATEGORY));

        Invoker invoker = cluster.join(directory);
//        生产者消费者注册表注册消费者=》
        ProviderConsumerRegTable.registerConsumer(invoker, url, subscribeUrl, directory);
        return invoker;
    }
 
Example 9
Source File: RegistryProtocol.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public void register(URL registryUrl, URL registedProviderUrl) {
//        查询注册器=》
        Registry registry = registryFactory.getRegistry(registryUrl);
//      服务注册=》FailbackRegistry.register() zookeeper://192.168.50.251:2181/com.alibaba.dubbo.registry.RegistryService?application=dubbo-provider&dubbo=2.0.2&interface=com.alibaba.dubbo.registry.RegistryService&pid=14414&timestamp=1573209627099
        registry.register(registedProviderUrl);
    }