Search in sources :

Example 31 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class Application method runWithRefer.

private static void runWithRefer() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
    reference.setInterface(DemoService.class);
    DemoService service = reference.get();
    String message = service.sayHello("dubbo");
    System.out.println(message);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService)

Example 32 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class Application method runWithBootstrap.

private static void runWithBootstrap() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setInterface(DemoService.class);
    reference.setGeneric("true");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer")).registry(new RegistryConfig("zookeeper://127.0.0.1:2181")).reference(reference).start();
    DemoService demoService = ReferenceConfigCache.getCache().get(reference);
    String message = demoService.sayHello("dubbo");
    System.out.println(message);
    // generic invoke
    GenericService genericService = (GenericService) demoService;
    Object genericInvokeResult = genericService.$invoke("sayHello", new String[] { String.class.getName() }, new Object[] { "dubbo generic invoke" });
    System.out.println(genericInvokeResult);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 33 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigValidationUtils method validateServiceConfig.

public static void validateServiceConfig(ServiceConfig config) {
    checkKey(VERSION_KEY, config.getVersion());
    checkKey(GROUP_KEY, config.getGroup());
    checkName(TOKEN_KEY, config.getToken());
    checkPathName(PATH_KEY, config.getPath());
    checkMultiExtension(ExporterListener.class, LISTENER_KEY, config.getListener());
    validateAbstractInterfaceConfig(config);
    List<RegistryConfig> registries = config.getRegistries();
    if (registries != null) {
        for (RegistryConfig registry : registries) {
            validateRegistryConfig(registry);
        }
    }
    List<ProtocolConfig> protocols = config.getProtocols();
    if (protocols != null) {
        for (ProtocolConfig protocol : protocols) {
            validateProtocolConfig(protocol);
        }
    }
    ProviderConfig providerConfig = config.getProvider();
    if (providerConfig != null) {
        validateProviderConfig(providerConfig);
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 34 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigValidationUtils method loadRegistries.

public static List<URL> loadRegistries(AbstractInterfaceConfig interfaceConfig, boolean provider) {
    // check && override if necessary
    List<URL> registryList = new ArrayList<URL>();
    ApplicationConfig application = interfaceConfig.getApplication();
    List<RegistryConfig> registries = interfaceConfig.getRegistries();
    if (CollectionUtils.isNotEmpty(registries)) {
        for (RegistryConfig config : registries) {
            String address = config.getAddress();
            if (StringUtils.isEmpty(address)) {
                address = ANYHOST_VALUE;
            }
            if (!RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
                Map<String, String> map = new HashMap<String, String>();
                AbstractConfig.appendParameters(map, application);
                AbstractConfig.appendParameters(map, config);
                map.put(PATH_KEY, RegistryService.class.getName());
                AbstractInterfaceConfig.appendRuntimeParameters(map);
                if (!map.containsKey(PROTOCOL_KEY)) {
                    map.put(PROTOCOL_KEY, DUBBO_PROTOCOL);
                }
                List<URL> urls = UrlUtils.parseURLs(address, map);
                if (urls == null) {
                    throw new IllegalStateException(String.format("url should not be null,address is %s", address));
                }
                for (URL url : urls) {
                    url = URLBuilder.from(url).addParameter(REGISTRY_KEY, url.getProtocol()).setProtocol(extractRegistryType(url)).build();
                    if ((provider && url.getParameter(REGISTER_KEY, true)) || (!provider && url.getParameter(SUBSCRIBE_KEY, true))) {
                        registryList.add(url);
                    }
                }
            }
        }
    }
    return genCompatibleRegistries(registryList, provider);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegistryService(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL)

Example 35 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigValidationUtils method validateReferenceConfig.

public static void validateReferenceConfig(ReferenceConfig config) {
    checkMultiExtension(InvokerListener.class, LISTENER_KEY, config.getListener());
    checkKey(VERSION_KEY, config.getVersion());
    checkKey(GROUP_KEY, config.getGroup());
    checkName(CLIENT_KEY, config.getClient());
    validateAbstractInterfaceConfig(config);
    List<RegistryConfig> registries = config.getRegistries();
    if (registries != null) {
        for (RegistryConfig registry : registries) {
            validateRegistryConfig(registry);
        }
    }
    ConsumerConfig consumerConfig = config.getConsumer();
    if (consumerConfig != null) {
        validateConsumerConfig(consumerConfig);
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig)

Aggregations

RegistryConfig (org.apache.dubbo.config.RegistryConfig)68 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)42 Test (org.junit.jupiter.api.Test)34 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)29 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)20 ServiceConfig (org.apache.dubbo.config.ServiceConfig)19 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 GenericService (org.apache.dubbo.rpc.service.GenericService)8 ArrayList (java.util.ArrayList)7 URL (org.apache.dubbo.common.URL)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ModuleConfig (org.apache.dubbo.config.ModuleConfig)4 MonitorConfig (org.apache.dubbo.config.MonitorConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 MethodConfig (org.apache.dubbo.config.MethodConfig)3