Search in sources :

Example 61 with ApplicationConfig

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

the class RegistryProtocolTest method setUp.

@BeforeEach
public void setUp() {
    ApplicationModel.setApplication("RegistryProtocolTest");
    ConfigManager configManager = ApplicationModel.getConfigManager();
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-provider");
    configManager.setApplication(applicationConfig);
    ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ConfigManager(org.apache.dubbo.config.context.ConfigManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 62 with ApplicationConfig

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

the class DubboBootstrap method getApplication.

public ApplicationConfig getApplication() {
    ApplicationConfig application = configManager.getApplication().orElseGet(() -> {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        configManager.setApplication(applicationConfig);
        return applicationConfig;
    });
    application.refresh();
    return application;
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig)

Example 63 with ApplicationConfig

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

the class DubboBootstrap method registerServiceInstance.

private void registerServiceInstance() {
    if (CollectionUtils.isEmpty(getServiceDiscoveries())) {
        return;
    }
    ApplicationConfig application = getApplication();
    String serviceName = application.getName();
    URL exportedURL = selectMetadataServiceExportedURL();
    String host = exportedURL.getHost();
    int port = exportedURL.getPort();
    ServiceInstance serviceInstance = createServiceInstance(serviceName, host, port);
    doRegisterServiceInstance(serviceInstance);
    // scheduled task for updating Metadata and ServiceInstance
    executorRepository.nextScheduledExecutor().scheduleAtFixedRate(() -> {
        try {
            InMemoryWritableMetadataService localMetadataService = (InMemoryWritableMetadataService) WritableMetadataService.getDefaultExtension();
            localMetadataService.blockUntilUpdated();
            ServiceInstanceMetadataUtils.refreshMetadataAndInstance();
        } catch (Throwable e) {
            logger.error("refresh metadata and instance failed", e);
        }
    }, 0, ConfigurationUtils.get(METADATA_PUBLISH_DELAY_KEY, DEFAULT_METADATA_PUBLISH_DELAY), TimeUnit.MILLISECONDS);
}
Also used : InMemoryWritableMetadataService(org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) URL(org.apache.dubbo.common.URL)

Example 64 with ApplicationConfig

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

the class DubboBootstrap method startMetadataCenter.

private void startMetadataCenter() {
    useRegistryAsMetadataCenterIfNecessary();
    ApplicationConfig applicationConfig = getApplication();
    String metadataType = applicationConfig.getMetadataType();
    // FIXME, multiple metadata config support.
    Collection<MetadataReportConfig> metadataReportConfigs = configManager.getMetadataConfigs();
    if (CollectionUtils.isEmpty(metadataReportConfigs)) {
        if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
            throw new IllegalStateException("No MetadataConfig found, Metadata Center address is required when 'metadata=remote' is enabled.");
        }
        return;
    }
    for (MetadataReportConfig metadataReportConfig : metadataReportConfigs) {
        ConfigValidationUtils.validateMetadataConfig(metadataReportConfig);
        if (!metadataReportConfig.isValid()) {
            continue;
        }
        MetadataReportInstance.init(metadataReportConfig);
    }
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig)

Example 65 with ApplicationConfig

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

the class ConfigValidationUtils method loadMonitor.

public static URL loadMonitor(AbstractInterfaceConfig interfaceConfig, URL registryURL) {
    Map<String, String> map = new HashMap<String, String>();
    map.put(INTERFACE_KEY, MonitorService.class.getName());
    AbstractInterfaceConfig.appendRuntimeParameters(map);
    // set ip
    String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
    if (StringUtils.isEmpty(hostToRegistry)) {
        hostToRegistry = NetUtils.getLocalHost();
    } else if (NetUtils.isInvalidLocalHost(hostToRegistry)) {
        throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
    }
    map.put(REGISTER_IP_KEY, hostToRegistry);
    MonitorConfig monitor = interfaceConfig.getMonitor();
    ApplicationConfig application = interfaceConfig.getApplication();
    AbstractConfig.appendParameters(map, monitor);
    AbstractConfig.appendParameters(map, application);
    String address = null;
    String sysaddress = System.getProperty(DUBBO_MONITOR_ADDRESS);
    if (sysaddress != null && sysaddress.length() > 0) {
        address = sysaddress;
    } else if (monitor != null) {
        address = monitor.getAddress();
    }
    if (ConfigUtils.isNotEmpty(address)) {
        if (!map.containsKey(PROTOCOL_KEY)) {
            if (getExtensionLoader(MonitorFactory.class).hasExtension(LOGSTAT_PROTOCOL)) {
                map.put(PROTOCOL_KEY, LOGSTAT_PROTOCOL);
            } else {
                map.put(PROTOCOL_KEY, DUBBO_PROTOCOL);
            }
        }
        return UrlUtils.parseURL(address, map);
    } else if (monitor != null && (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol())) && registryURL != null) {
        return URLBuilder.from(registryURL).setProtocol(DUBBO_PROTOCOL).addParameter(PROTOCOL_KEY, monitor.getProtocol()).addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map)).build();
    }
    return null;
}
Also used : MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) HashMap(java.util.HashMap) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MonitorService(org.apache.dubbo.monitor.MonitorService) MonitorConfig(org.apache.dubbo.config.MonitorConfig)

Aggregations

ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)75 RegistryConfig (org.apache.dubbo.config.RegistryConfig)42 Test (org.junit.jupiter.api.Test)32 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)27 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)19 ServiceConfig (org.apache.dubbo.config.ServiceConfig)18 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 URL (org.apache.dubbo.common.URL)9 GenericService (org.apache.dubbo.rpc.service.GenericService)8 Test (org.junit.Test)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 MonitorConfig (org.apache.dubbo.config.MonitorConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AbstractInterfaceConfigTest (org.apache.dubbo.config.AbstractInterfaceConfigTest)4 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)4 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)3 ModuleConfig (org.apache.dubbo.config.ModuleConfig)3 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)3