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();
}
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);
}
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());
}
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);
}
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;
}
Aggregations