Search in sources :

Example 56 with RegistryConfig

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

the class EnableDubboConfigTest method testSingle.

@Test
public void testSingle() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(TestConfig.class);
    context.refresh();
    // application
    ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
    Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
    // module
    ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
    Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName());
    // registry
    RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
    Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());
    // protocol
    ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
    Assertions.assertEquals("dubbo", protocolConfig.getName());
    Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
    // monitor
    MonitorConfig monitorConfig = context.getBean(MonitorConfig.class);
    Assertions.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress());
    // provider
    ProviderConfig providerConfig = context.getBean(ProviderConfig.class);
    Assertions.assertEquals("127.0.0.1", providerConfig.getHost());
    // consumer
    ConsumerConfig consumerConfig = context.getBean(ConsumerConfig.class);
    Assertions.assertEquals("netty", consumerConfig.getClient());
    // asserts aliases
    assertFalse(hasAlias(context, "org.apache.dubbo.config.RegistryConfig#0", "zookeeper"));
    assertFalse(hasAlias(context, "org.apache.dubbo.config.MonitorConfig#0", "zookeeper"));
    context.close();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) ModuleConfig(org.apache.dubbo.config.ModuleConfig) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) MonitorConfig(org.apache.dubbo.config.MonitorConfig) Test(org.junit.jupiter.api.Test)

Example 57 with RegistryConfig

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

the class ConsumerConfiguration method registryConfig.

/**
 * Current registry center configuration, to replace XML config:
 * <prev>
 * &lt;dubbo:registry address="N/A"/&gt;
 * </prev>
 *
 * @return {@link RegistryConfig} Bean
 */
@Bean
public RegistryConfig registryConfig() {
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("N/A");
    return registryConfig;
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Bean(org.springframework.context.annotation.Bean)

Example 58 with RegistryConfig

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

the class LazyInitDubboAnnotationTest method registryConfig.

/**
 * lazy-init Registry Configuration
 *
 * @return {@link RegistryConfig} Bean
 */
@Bean("registryConfig")
public RegistryConfig registryConfig() {
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("N/A");
    return registryConfig;
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Bean(org.springframework.context.annotation.Bean)

Example 59 with RegistryConfig

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

the class EnableDubboTest method testConsumer.

@Test
public void testConsumer() {
    context.register(TestProviderConfiguration.class, TestConsumerConfiguration.class);
    context.refresh();
    TestConsumerConfiguration consumerConfiguration = context.getBean(TestConsumerConfiguration.class);
    DemoService demoService = consumerConfiguration.getDemoService();
    String value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    DemoService autowiredDemoService = consumerConfiguration.getAutowiredDemoService();
    Assertions.assertEquals("Hello,Mercy", autowiredDemoService.sayName("Mercy"));
    TestConsumerConfiguration.Child child = context.getBean(TestConsumerConfiguration.Child.class);
    // From Child
    demoService = child.getDemoServiceFromChild();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Parent
    demoService = child.getDemoServiceFromParent();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Ancestor
    demoService = child.getDemoServiceFromAncestor();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // Test my-registry2 bean presentation
    RegistryConfig registryConfig = context.getBean("my-registry2", RegistryConfig.class);
    // Test multiple binding
    Assertions.assertEquals("N/A", registryConfig.getAddress());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) TestConsumerConfiguration(org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration) DemoService(org.apache.dubbo.config.spring.api.DemoService) Test(org.junit.jupiter.api.Test)

Example 60 with RegistryConfig

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

the class DubboBootstrap method loadRemoteConfigs.

private void loadRemoteConfigs() {
    // registry ids to registry configs
    List<RegistryConfig> tmpRegistries = new ArrayList<>();
    Set<String> registryIds = configManager.getRegistryIds();
    registryIds.forEach(id -> {
        if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) {
            tmpRegistries.add(configManager.getRegistry(id).orElseGet(() -> {
                RegistryConfig registryConfig = new RegistryConfig();
                registryConfig.setId(id);
                registryConfig.refresh();
                return registryConfig;
            }));
        }
    });
    configManager.addRegistries(tmpRegistries);
    // protocol ids to protocol configs
    List<ProtocolConfig> tmpProtocols = new ArrayList<>();
    Set<String> protocolIds = configManager.getProtocolIds();
    protocolIds.forEach(id -> {
        if (tmpProtocols.stream().noneMatch(prot -> prot.getId().equals(id))) {
            tmpProtocols.add(configManager.getProtocol(id).orElseGet(() -> {
                ProtocolConfig protocolConfig = new ProtocolConfig();
                protocolConfig.setId(id);
                protocolConfig.refresh();
                return protocolConfig;
            }));
        }
    });
    configManager.addProtocols(tmpProtocols);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ArrayList(java.util.ArrayList) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

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