Search in sources :

Example 11 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig 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 12 with ConsumerConfig

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

the class DubboBootstrap method checkGlobalConfigs.

private void checkGlobalConfigs() {
    // check Application
    ConfigValidationUtils.validateApplicationConfig(getApplication());
    // check Metadata
    Collection<MetadataReportConfig> metadatas = configManager.getMetadataConfigs();
    if (CollectionUtils.isEmpty(metadatas)) {
        MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
        metadataReportConfig.refresh();
        if (metadataReportConfig.isValid()) {
            configManager.addMetadataReport(metadataReportConfig);
            metadatas = configManager.getMetadataConfigs();
        }
    }
    if (CollectionUtils.isNotEmpty(metadatas)) {
        for (MetadataReportConfig metadataReportConfig : metadatas) {
            metadataReportConfig.refresh();
            ConfigValidationUtils.validateMetadataConfig(metadataReportConfig);
        }
    }
    // check Provider
    Collection<ProviderConfig> providers = configManager.getProviders();
    if (CollectionUtils.isEmpty(providers)) {
        configManager.getDefaultProvider().orElseGet(() -> {
            ProviderConfig providerConfig = new ProviderConfig();
            configManager.addProvider(providerConfig);
            providerConfig.refresh();
            return providerConfig;
        });
    }
    for (ProviderConfig providerConfig : configManager.getProviders()) {
        ConfigValidationUtils.validateProviderConfig(providerConfig);
    }
    // check Consumer
    Collection<ConsumerConfig> consumers = configManager.getConsumers();
    if (CollectionUtils.isEmpty(consumers)) {
        configManager.getDefaultConsumer().orElseGet(() -> {
            ConsumerConfig consumerConfig = new ConsumerConfig();
            configManager.addConsumer(consumerConfig);
            consumerConfig.refresh();
            return consumerConfig;
        });
    }
    for (ConsumerConfig consumerConfig : configManager.getConsumers()) {
        ConfigValidationUtils.validateConsumerConfig(consumerConfig);
    }
    // check Monitor
    ConfigValidationUtils.validateMonitorConfig(getMonitor());
    // check Metrics
    ConfigValidationUtils.validateMetricsConfig(getMetrics());
    // check Module
    ConfigValidationUtils.validateModuleConfig(getModule());
    // check Ssl
    ConfigValidationUtils.validateSslConfig(getSsl());
}
Also used : ProviderConfig(org.apache.dubbo.config.ProviderConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig)

Aggregations

ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)12 Test (org.junit.jupiter.api.Test)7 RegistryConfig (org.apache.dubbo.config.RegistryConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)3 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 DemoService (org.apache.dubbo.config.api.DemoService)2 URL (org.apache.dubbo.common.URL)1 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)1 ModuleConfig (org.apache.dubbo.config.ModuleConfig)1 MonitorConfig (org.apache.dubbo.config.MonitorConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1