Java Code Examples for com.alibaba.dubbo.config.ProtocolConfig#setPort()
The following examples show how to use
com.alibaba.dubbo.config.ProtocolConfig#setPort() .
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: DubboProviderBootstrap.java From sofa-rpc with Apache License 2.0 | 6 votes |
private void copyServerFields(ServerConfig serverConfig, ProtocolConfig protocolConfig) { protocolConfig.setId(serverConfig.getId()); protocolConfig.setName(serverConfig.getProtocol()); protocolConfig.setHost(serverConfig.getHost()); protocolConfig.setPort(serverConfig.getPort()); protocolConfig.setAccepts(serverConfig.getAccepts()); protocolConfig.setSerialization(serverConfig.getSerialization()); if (!StringUtils.CONTEXT_SEP.equals(serverConfig.getContextPath())) { protocolConfig.setContextpath(serverConfig.getContextPath()); } protocolConfig.setIothreads(serverConfig.getIoThreads()); protocolConfig.setThreadpool(serverConfig.getThreadPoolType()); protocolConfig.setThreads(serverConfig.getMaxThreads()); protocolConfig.setPayload(serverConfig.getPayload()); protocolConfig.setQueues(serverConfig.getQueues()); protocolConfig.setParameters(serverConfig.getParameters()); }
Example 2
Source File: DubboAutoConfiguration.java From spring-boot-starter-dubbo with Apache License 2.0 | 6 votes |
private void registerProtocols(List<ProtocolConfig> protocols, ConfigurableListableBeanFactory beanFactory) { if (protocols == null || protocols.isEmpty()) { logger.info("dubbo 没有配置协议,将使用默认协议"); return; } for (int index = 0; index < protocols.size(); index++) { ProtocolConfig protocol = protocols.get(index); String beanName = protocol.getId(); if (StringUtils.isEmpty(beanName)) { beanName = "protocolConfig" + index; } if (protocol.getPort() == null || protocol.getPort() == 0) { protocol.setPort(SocketUtils.findAvailableTcpPort(53600, 53688)); } beanFactory.registerSingleton(beanName, protocol); logger.debug("注册协议信息{}完毕", beanName); } }
Example 3
Source File: ConfigTest.java From dubbox 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 4
Source File: DubboConfiguration.java From cicada with MIT License | 5 votes |
@Bean public ProtocolConfig dubboProtocol() { final ProtocolConfig protocol = new ProtocolConfig(); protocol.setName(dubboProperty.getProtocolName()); protocol.setPort(dubboProperty.getProtocolPort()); return protocol; }
Example 5
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 6
Source File: DubboConfig.java From dubbox-zookeeper-demo with Apache License 2.0 | 5 votes |
@Bean public ProtocolConfig protocalConfig(){ ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setName(getProtocolName()); protocolConfig.setPort(getProtocalPort()); return protocolConfig; }
Example 7
Source File: DubboConfig.java From dubbox-zookeeper-demo with Apache License 2.0 | 5 votes |
@Bean public ProtocolConfig protocalConfig(){ ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setName(getProtocolName()); protocolConfig.setPort(getProtocalPort()); return protocolConfig; }
Example 8
Source File: ConfigTest.java From dubbox-hystrix 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 9
Source File: ConfigTest.java From dubbox 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: DubboConfig.java From swagger-dubbo with Apache License 2.0 | 5 votes |
@Bean public ProtocolConfig protocolConfig() { ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(29880); return protocol; }
Example 11
Source File: ConfigTest.java From dubbo-2.6.5 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 12
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@Test public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); 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("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); reference.get(); try { url = reference.toUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 13
Source File: ConfigTest.java From dubbox-hystrix 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", ""); } }
Example 14
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", ""); } }
Example 15
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); 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("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); reference.get(); try { url = reference.toUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 16
Source File: AlibabaDubboInstrumentationTest.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Override protected DubboTestApi buildDubboTestApi() { ApplicationConfig providerAppConfig = new ApplicationConfig(); providerAppConfig.setName("dubbo-provider"); ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setName("dubbo"); protocolConfig.setPort(getPort()); protocolConfig.setThreads(10); RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("N/A"); serviceConfig = new ServiceConfig<>(); serviceConfig.setApplication(providerAppConfig); serviceConfig.setProtocol(protocolConfig); serviceConfig.setInterface(DubboTestApi.class); serviceConfig.setRef(new DubboTestApiImpl()); serviceConfig.setRegistry(registryConfig); serviceConfig.export(); ApplicationConfig consumerApp = new ApplicationConfig(); consumerApp.setName("dubbo-consumer"); referenceConfig = new ReferenceConfig<>(); referenceConfig.setApplication(consumerApp); referenceConfig.setInterface(DubboTestApi.class); referenceConfig.setUrl("dubbo://localhost:" + getPort()); referenceConfig.setTimeout(3000); List<MethodConfig> methodConfigList = new LinkedList<>(); referenceConfig.setMethods(methodConfigList); MethodConfig asyncConfig = new MethodConfig(); asyncConfig.setName("async"); asyncConfig.setAsync(true); methodConfigList.add(asyncConfig); MethodConfig asyncNoReturnConfig = new MethodConfig(); asyncNoReturnConfig.setName("asyncNoReturn"); asyncNoReturnConfig.setAsync(true); asyncNoReturnConfig.setReturn(false); methodConfigList.add(asyncNoReturnConfig); return referenceConfig.get(); }
Example 17
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 4 votes |
@Test public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); 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("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); reference.get(); try { url = reference.toUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 18
Source File: ConfigTest.java From dubbo3 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", ""); } }
Example 19
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); 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("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); reference.get(); try { url = reference.toUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 20
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Test public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); 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("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); reference.get(); try { url = reference.toUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { reference.destroy(); } } finally { service.unexport(); } }