Search in sources :

Example 11 with RegistryConfig

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

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

the class ApplicationBuilderTest method addRegistry.

@Test
void addRegistry() {
    RegistryConfig registry = new RegistryConfig();
    ApplicationBuilder builder = new ApplicationBuilder();
    builder.addRegistry(registry);
    Assertions.assertNotNull(builder.build().getRegistry());
    Assertions.assertEquals(1, builder.build().getRegistries().size());
    Assertions.assertSame(registry, builder.build().getRegistry());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Test(org.junit.jupiter.api.Test)

Example 13 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig 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)

Example 14 with RegistryConfig

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

the class DubboInterfaceConsumerBootstrap method main.

public static void main(String[] args) throws Exception {
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application("dubbo-consumer-demo").registry(interfaceRegistry).reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo")).reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest")).start().await();
    EchoService echoService = bootstrap.getCache().get(EchoService.class);
    UserService userService = bootstrap.getCache().get(UserService.class);
    for (int i = 0; i < 500; i++) {
        Thread.sleep(2000L);
        System.out.println(echoService.echo("Hello,World"));
        System.out.println(userService.getUser(1L));
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) RegistryConfig(org.apache.dubbo.config.RegistryConfig) EchoService(org.apache.dubbo.config.bootstrap.EchoService) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) EchoService(org.apache.dubbo.config.bootstrap.EchoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 15 with RegistryConfig

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

the class ConfigTest method testDubboProtocolPortOverride.

@Test
public void testDubboProtocolPortOverride() throws Exception {
    String dubboPort = System.getProperty("dubbo.protocol.dubbo.port");
    int port = 55555;
    System.setProperty("dubbo.protocol.dubbo.port", String.valueOf(port));
    ServiceConfig<DemoService> service = null;
    DubboBootstrap bootstrap = null;
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-protocol-port-override");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");
        ProtocolConfig protocol = new ProtocolConfig();
        service = new ServiceConfig<DemoService>();
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
        Assertions.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (bootstrap != null) {
            bootstrap.stop();
        }
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) Matchers.containsString(org.hamcrest.Matchers.containsString) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryConfig (org.apache.dubbo.config.RegistryConfig)68 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)42 Test (org.junit.jupiter.api.Test)34 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)29 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)20 ServiceConfig (org.apache.dubbo.config.ServiceConfig)19 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 GenericService (org.apache.dubbo.rpc.service.GenericService)8 ArrayList (java.util.ArrayList)7 URL (org.apache.dubbo.common.URL)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ModuleConfig (org.apache.dubbo.config.ModuleConfig)4 MonitorConfig (org.apache.dubbo.config.MonitorConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 MethodConfig (org.apache.dubbo.config.MethodConfig)3