Java Code Examples for com.alibaba.dubbo.config.RegistryConfig#setAddress()
The following examples show how to use
com.alibaba.dubbo.config.RegistryConfig#setAddress() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIConfigurationLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void givenProviderConsumer_whenSayHi_thenGotResponse() { ApplicationConfig application = new ApplicationConfig(); application.setName("demo-consumer"); application.setVersion("1.0"); RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("multicast://224.1.1.1:9090"); ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>(); reference.setApplication(application); reference.setRegistry(registryConfig); reference.setInterface(GreetingsService.class); GreetingsService greetingsService = reference.get(); String hiMessage = greetingsService.sayHi("baeldung"); assertEquals("hi, baeldung", hiMessage); }
Example 2
Source File: DubboConfiguration.java From cicada with MIT License | 5 votes |
@Bean public List<RegistryConfig> dubboRegistries() { List<RegistryConfig> registrConfigs = new ArrayList<RegistryConfig>(); String zkUrls = dubboProperty.getZkUrls(); if (StringUtils.isNotBlank(zkUrls)) { String[] zkUrlsArr = zkUrls.split(","); for (String zkUrl : zkUrlsArr) { RegistryConfig registry = new RegistryConfig(); registry.setAddress(zkUrl); registry.setProtocol("zookeeper"); registrConfigs.add(registry); } } return registrConfigs; }
Example 3
Source File: InvokerSideConfigUrlTest.java From dubbox with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example 4
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>(); sc.setApplication(ac); sc.setRegistry(rc); sc.setInterface(DemoService.class.getName()); sc.setRef(new GenericService() { public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example 5
Source File: InvokerSideConfigUrlTest.java From dubbo3 with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example 6
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>(); sc.setApplication(ac); sc.setRegistry(rc); sc.setInterface(DemoService.class.getName()); sc.setRef(new GenericService() { public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example 7
Source File: UrlTestBase.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example 8
Source File: DubboServiceConfig.java From dubbo-mock with Apache License 2.0 | 5 votes |
public static RegistryConfig createRegistry(String address, int timeout) { RegistryConfig registry = new RegistryConfig(); registry.setProtocol("zookeeper"); registry.setAddress(address); registry.setTimeout(timeout); return registry; }
Example 9
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void testProtocolRandomPort() throws Exception { ServiceConfig<DemoService> demoService = null; ServiceConfig<HelloService> helloService = null; ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(-1); demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); helloService = new ServiceConfig<HelloService>(); helloService.setInterface(HelloService.class); helloService.setRef(new HelloServiceImpl()); helloService.setApplication(application); helloService.setRegistry(registry); helloService.setProtocol(protocol); try { demoService.export(); helloService.export(); Assert.assertEquals(demoService.getExportedUrls().get(0).getPort(), helloService.getExportedUrls().get(0).getPort()); } finally { unexportService(demoService); unexportService(helloService); } }
Example 10
Source File: UrlTestBase.java From dubbo3 with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example 11
Source File: DubboUtils.java From java-master with Apache License 2.0 | 5 votes |
private static RegistryConfig getRegistryConfig(String group, String version) { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress(DubboUtils.ZOOKEEPER_ADDRESS); registryConfig.setVersion(version); registryConfig.setGroup(group); registryConfig.setTimeout(30000); return registryConfig; }
Example 12
Source File: UrlTestBase.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example 13
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@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; 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); service.export(); Assert.assertEquals(port, service.getExportedUrls().get(0).getPort()); } finally { if (StringUtils.isNotEmpty(dubboPort)) { System.setProperty("dubbo.protocol.dubbo.port", dubboPort); } if (service != null) { service.unexport(); } } }
Example 14
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>(); sc.setApplication(ac); sc.setRegistry(rc); sc.setInterface(DemoService.class.getName()); sc.setRef(new GenericService() { public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example 15
Source File: InvokerSideConfigUrlTest.java From dubbox with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example 16
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@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; 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); service.export(); Assert.assertEquals(port, service.getExportedUrls().get(0).getPort()); } finally { if (StringUtils.isNotEmpty(dubboPort)) { System.setProperty("dubbo.protocol.dubbo.port", dubboPort); } if (service != null) { service.unexport(); } } }
Example 17
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testSystemPropertyOverrideProperties() throws Exception { String portString = System.getProperty( "dubbo.protocol.port"); System.clearProperty("dubbo.protocol.port"); try { int port = 1234; System.setProperty("dubbo.protocol.port", String.valueOf(port)); ApplicationConfig application = new ApplicationConfig(); application.setName("aaa"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("rmi"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.setApplication(application); service.setRegistry(registry); service.setProtocol(protocol); service.export(); try { URL url = service.toUrls().get(0); // from api assertEquals("aaa", url.getParameter("application")); // from dubbo.properties assertEquals("world", url.getParameter("owner")); // from system property assertEquals(1234, url.getPort()); } finally { service.unexport(); } } finally { if (portString != null) { System.setProperty("dubbo.protocol.port", portString); } } }
Example 18
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testSystemPropertyOverrideProperties() throws Exception { String portString = System.getProperty( "dubbo.protocol.port"); System.clearProperty("dubbo.protocol.port"); try { int port = 1234; System.setProperty("dubbo.protocol.port", String.valueOf(port)); ApplicationConfig application = new ApplicationConfig(); application.setName("aaa"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("rmi"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.setApplication(application); service.setRegistry(registry); service.setProtocol(protocol); service.export(); try { URL url = service.toUrls().get(0); // from api assertEquals("aaa", url.getParameter("application")); // from dubbo.properties assertEquals("world", url.getParameter("owner")); // from system property assertEquals(1234, url.getPort()); } finally { service.unexport(); } } finally { if (portString != null) { System.setProperty("dubbo.protocol.port", portString); } } }
Example 19
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Test public void testSystemPropertyOverrideProperties() throws Exception { String portString = System.getProperty("dubbo.protocol.port"); System.clearProperty("dubbo.protocol.port"); try { int port = 1234; System.setProperty("dubbo.protocol.port", String.valueOf(port)); ApplicationConfig application = new ApplicationConfig(); application.setName("aaa"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("rmi"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.setApplication(application); service.setRegistry(registry); service.setProtocol(protocol); service.export(); try { URL url = service.toUrls().get(0); // from api assertEquals("aaa", url.getParameter("application")); // from dubbo.properties assertEquals("world", url.getParameter("owner")); // from system property assertEquals(1234, url.getPort()); } finally { service.unexport(); } } finally { if (portString != null) { System.setProperty("dubbo.protocol.port", portString); } } }
Example 20
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testSystemPropertyOverrideApi() throws Exception { System.setProperty("dubbo.application.name", "sysover"); System.setProperty("dubbo.application.owner", "sysowner"); System.setProperty("dubbo.registry.address", "N/A"); System.setProperty("dubbo.protocol.name", "dubbo"); System.setProperty("dubbo.protocol.port", "20834"); try { ApplicationConfig application = new ApplicationConfig(); application.setName("aaa"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("127.0.0.1"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("rmi"); protocol.setPort(1099); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.setApplication(application); service.setRegistry(registry); service.setProtocol(protocol); service.export(); try { URL url = service.toUrls().get(0); assertEquals("sysover", url.getParameter("application")); assertEquals("sysowner", url.getParameter("owner")); assertEquals("dubbo", url.getProtocol()); assertEquals(20834, url.getPort()); } finally { service.unexport(); } } finally { System.setProperty("dubbo.application.name", ""); System.setProperty("dubbo.application.owner", ""); System.setProperty("dubbo.registry.address", ""); System.setProperty("dubbo.protocol.name", ""); System.setProperty("dubbo.protocol.port", ""); } }