Search in sources :

Example 11 with ApplicationConfig

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

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

the class EtcdDubboServiceProviderBootstrap 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("etcd3://127.0.0.1:2379");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("etcd3://127.0.0.1:2379?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")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) 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) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 13 with ApplicationConfig

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

the class NacosDubboServiceProviderBootstrap method main.

public static void main(String[] args) {
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-nacos-provider-demo");
    applicationConfig.setMetadataType(REMOTE_METADATA_STORAGE_TYPE);
    DubboBootstrap.getInstance().application(applicationConfig).registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?username=nacos&password=nacos").parameter(REGISTRY_TYPE_KEY, SERVICE_REGISTRY_TYPE)).protocol("dubbo", builder -> builder.port(20885).name("dubbo")).protocol("rest", builder -> builder.port(9090).name("rest")).service(builder -> builder.id("echo").interfaceClass(EchoService.class).ref(new EchoServiceImpl()).protocolIds("dubbo")).service(builder -> builder.id("user").interfaceClass(UserService.class).ref(new UserServiceImpl()).protocolIds("rest")).start().await();
}
Also used : REMOTE_METADATA_STORAGE_TYPE(org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) REGISTRY_TYPE_KEY(org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY) SERVICE_REGISTRY_TYPE(org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)

Example 14 with ApplicationConfig

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

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

the class ApplicationBuilderTest method build.

@Test
void build() {
    MonitorConfig monitor = new MonitorConfig("monitor-addr");
    RegistryConfig registry = new RegistryConfig();
    ApplicationBuilder builder = new ApplicationBuilder();
    builder.id("id").prefix("prefix").name("name").version("version").owner("owner").organization("organization").architecture("architecture").environment("develop").compiler("compiler").logger("log4j").monitor(monitor).isDefault(false).dumpDirectory("dumpDirectory").qosEnable(true).qosPort(8080).qosAcceptForeignIp(false).shutwait("shutwait").registryIds("registryIds").addRegistry(registry).appendParameter("default.num", "one").metadataServicePort(12345);
    ApplicationConfig config = builder.build();
    ApplicationConfig config2 = builder.build();
    Assertions.assertEquals("id", config.getId());
    Assertions.assertEquals("prefix", config.getPrefix());
    Assertions.assertEquals("name", config.getName());
    Assertions.assertEquals("version", config.getVersion());
    Assertions.assertEquals("owner", config.getOwner());
    Assertions.assertEquals("organization", config.getOrganization());
    Assertions.assertEquals("architecture", config.getArchitecture());
    Assertions.assertEquals("develop", config.getEnvironment());
    Assertions.assertEquals("compiler", config.getCompiler());
    Assertions.assertEquals("log4j", config.getLogger());
    Assertions.assertSame(monitor, config.getMonitor());
    Assertions.assertFalse(config.isDefault());
    Assertions.assertEquals("dumpDirectory", config.getDumpDirectory());
    Assertions.assertTrue(config.getQosEnable());
    Assertions.assertEquals(8080, config.getQosPort());
    Assertions.assertFalse(config.getQosAcceptForeignIp());
    Assertions.assertEquals("shutwait", config.getShutwait());
    Assertions.assertEquals("registryIds", config.getRegistryIds());
    Assertions.assertSame(registry, config.getRegistry());
    Assertions.assertTrue(config.getParameters().containsKey("default.num"));
    Assertions.assertEquals("one", config.getParameters().get("default.num"));
    Assertions.assertEquals(12345, config.getMetadataServicePort());
    Assertions.assertNotSame(config, config2);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MonitorConfig(org.apache.dubbo.config.MonitorConfig) Test(org.junit.jupiter.api.Test)

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