Search in sources :

Example 1 with MetadataReportConfig

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

the class DubboServiceProviderBootstrap method multipleRegistries.

private static void multipleRegistries() {
    ProtocolConfig restProtocol = new ProtocolConfig();
    restProtocol.setName("rest");
    restProtocol.setId("rest");
    restProtocol.setPort(-1);
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
    ServiceConfig<EchoService> echoService = new ServiceConfig<>();
    echoService.setInterface(EchoService.class.getName());
    echoService.setRef(new EchoServiceImpl());
    // echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ServiceConfig<UserService> userService = new ServiceConfig<>();
    userService.setInterface(UserService.class.getName());
    userService.setRef(new UserServiceImpl());
    userService.setProtocol(restProtocol);
    // userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
    applicationConfig.setMetadataType("remote");
    DubboBootstrap.getInstance().application(applicationConfig).registries(Arrays.asList(interfaceRegistry, serviceRegistry)).protocol(builder -> builder.port(-1).name("dubbo")).metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Arrays(java.util.Arrays) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 2 with MetadataReportConfig

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

the class AbstractInterfaceBuilderTest method build.

@Test
void build() {
    MonitorConfig monitorConfig = new MonitorConfig("123");
    ApplicationConfig applicationConfig = new ApplicationConfig();
    ModuleConfig moduleConfig = new ModuleConfig();
    RegistryConfig registryConfig = new RegistryConfig();
    MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
    ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
    InterfaceBuilder builder = new InterfaceBuilder();
    builder.id("id").prefix("prefix").local(true).stub(false).monitor("123").proxy("mockproxyfactory").cluster("mockcluster").filter("mockfilter").listener("mockinvokerlistener").owner("owner").connections(1).layer("layer").application(applicationConfig).module(moduleConfig).addRegistry(registryConfig).registryIds("registryIds").onconnect("onconnet").ondisconnect("ondisconnect").metadataReportConfig(metadataReportConfig).configCenter(configCenterConfig).callbacks(2).scope("scope");
    InterfaceConfig config = builder.build();
    InterfaceConfig config2 = builder.build();
    Assertions.assertEquals("id", config.getId());
    Assertions.assertEquals("prefix", config.getPrefix());
    Assertions.assertEquals("true", config.getLocal());
    Assertions.assertEquals("false", config.getStub());
    Assertions.assertEquals(monitorConfig, config.getMonitor());
    Assertions.assertEquals("mockproxyfactory", config.getProxy());
    Assertions.assertEquals("mockcluster", config.getCluster());
    Assertions.assertEquals("mockfilter", config.getFilter());
    Assertions.assertEquals("mockinvokerlistener", config.getListener());
    Assertions.assertEquals("owner", config.getOwner());
    Assertions.assertEquals(1, config.getConnections().intValue());
    Assertions.assertEquals("layer", config.getLayer());
    Assertions.assertEquals(applicationConfig, config.getApplication());
    Assertions.assertEquals(moduleConfig, config.getModule());
    Assertions.assertEquals(registryConfig, config.getRegistry());
    Assertions.assertEquals("registryIds", config.getRegistryIds());
    Assertions.assertEquals("onconnet", config.getOnconnect());
    Assertions.assertEquals("ondisconnect", config.getOndisconnect());
    Assertions.assertEquals(metadataReportConfig, config.getMetadataReportConfig());
    Assertions.assertEquals(configCenterConfig, config.getConfigCenter());
    Assertions.assertEquals(2, config.getCallbacks().intValue());
    Assertions.assertEquals("scope", config.getScope());
    Assertions.assertNotSame(config, config2);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ConfigCenterConfig(org.apache.dubbo.config.ConfigCenterConfig) AbstractInterfaceConfig(org.apache.dubbo.config.AbstractInterfaceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ModuleConfig(org.apache.dubbo.config.ModuleConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) MonitorConfig(org.apache.dubbo.config.MonitorConfig) Test(org.junit.jupiter.api.Test)

Example 3 with MetadataReportConfig

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

the class AbstractInterfaceBuilderTest method metadataReportConfig.

@Test
void metadataReportConfig() {
    MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
    InterfaceBuilder builder = new InterfaceBuilder();
    builder.metadataReportConfig(metadataReportConfig);
    Assertions.assertEquals(metadataReportConfig, builder.build().getMetadataReportConfig());
}
Also used : MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) Test(org.junit.jupiter.api.Test)

Example 4 with MetadataReportConfig

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

the class MetadataReportBuilderTest method build.

@Test
void build() {
    MetadataReportBuilder builder = new MetadataReportBuilder();
    builder.address("address").username("username").password("password").timeout(1000).group("group").retryTimes(1).retryPeriod(2).cycleReport(true).syncReport(false).file("file").appendParameter("default.num", "one").id("id").prefix("prefix");
    MetadataReportConfig config = builder.build();
    MetadataReportConfig config2 = builder.build();
    Assertions.assertTrue(config.getCycleReport());
    Assertions.assertFalse(config.getSyncReport());
    Assertions.assertEquals(1000, config.getTimeout());
    Assertions.assertEquals(1, config.getRetryTimes());
    Assertions.assertEquals(2, config.getRetryPeriod());
    Assertions.assertEquals("address", config.getAddress());
    Assertions.assertEquals("username", config.getUsername());
    Assertions.assertEquals("password", config.getPassword());
    Assertions.assertEquals("group", config.getGroup());
    Assertions.assertEquals("file", config.getFile());
    Assertions.assertTrue(config.getParameters().containsKey("default.num"));
    Assertions.assertEquals("one", config.getParameters().get("default.num"));
    Assertions.assertEquals("id", config.getId());
    Assertions.assertEquals("prefix", config.getPrefix());
    Assertions.assertNotSame(config, config2);
}
Also used : MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) Test(org.junit.jupiter.api.Test)

Example 5 with MetadataReportConfig

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

the class DubboBootstrap method registryAsMetadataCenter.

private MetadataReportConfig registryAsMetadataCenter(RegistryConfig registryConfig) {
    String protocol = registryConfig.getProtocol();
    Integer port = registryConfig.getPort();
    String id = "metadata-center-" + protocol + "-" + port;
    if (configManager.getMetadataConfig(id) != null) {
        return null;
    }
    MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
    metadataReportConfig.setId(id);
    if (metadataReportConfig.getParameters() == null) {
        metadataReportConfig.setParameters(new HashMap<>());
    }
    if (registryConfig.getParameters() != null) {
        // copy the parameters
        metadataReportConfig.getParameters().putAll(registryConfig.getParameters());
    }
    metadataReportConfig.getParameters().put(CLIENT_KEY, registryConfig.getClient());
    metadataReportConfig.setGroup(registryConfig.getGroup());
    metadataReportConfig.setAddress(getRegistryCompatibleAddress(registryConfig));
    metadataReportConfig.setUsername(registryConfig.getUsername());
    metadataReportConfig.setPassword(registryConfig.getPassword());
    metadataReportConfig.setTimeout(registryConfig.getTimeout());
    return metadataReportConfig;
}
Also used : MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig)

Aggregations

MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)8 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)3 Test (org.junit.jupiter.api.Test)3 RegistryConfig (org.apache.dubbo.config.RegistryConfig)2 Arrays (java.util.Arrays)1 AbstractInterfaceConfig (org.apache.dubbo.config.AbstractInterfaceConfig)1 ConfigCenterConfig (org.apache.dubbo.config.ConfigCenterConfig)1 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)1 ModuleConfig (org.apache.dubbo.config.ModuleConfig)1 MonitorConfig (org.apache.dubbo.config.MonitorConfig)1 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)1 ProviderConfig (org.apache.dubbo.config.ProviderConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)1 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)1