Java Code Examples for com.alibaba.dubbo.config.ServiceConfig#setProvider()
The following examples show how to use
com.alibaba.dubbo.config.ServiceConfig#setProvider() .
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: DubboConfiguration.java From cicada with MIT License | 5 votes |
@Bean public ServiceConfig<DemoService> dubboDemoSerive() { final ServiceConfig<DemoService> dubboService = new ServiceConfig<>();// 该类很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏 dubboService.setApplication(this.dubboApplication()); dubboService.setRegistries(this.dubboRegistries()); // 多个注册中心可以用setRegistries() dubboService.setProvider(dubboProvider()); dubboService.setInterface(DemoService.class); dubboService.setRef(demoService); dubboService.export(); return dubboService; }
Example 2
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 3
Source File: DubboEasyTransRpcProviderImpl.java From EasyTransaction with Apache License 2.0 | 4 votes |
@Override public void startService(Class<?> businessInterface,Map<BusinessIdentifer, RpcBusinessProvider<?>> businessList) { for(Entry<BusinessIdentifer, RpcBusinessProvider<?>> entry :businessList.entrySet()){ BusinessIdentifer key = entry.getKey(); final RpcBusinessProvider<?> value = entry.getValue(); GenericService genericService = new GenericService() { @Override public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { //第一个参数类型为easytransRequest,第二个为map(业务外 框架用的元数据) Method callMethod = getMethod(value.getClass(),method,new String[]{parameterTypes[0]}); try { Object invokeResult = callMethod.invoke(value, new Object[]{args[0]}); logger.debug("EasyTrans rpc call recived, executed success:" + args[0]); return invokeResult; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { logger.info("EasyTrans rpc call recived,executed failed:" + args[0], e); throw new RuntimeException(e); } } }; ServiceConfig<GenericService> service = new ServiceConfig<GenericService>(); service.setInterface(businessInterface); service.setGroup(key.appId() + "-" + key.busCode()); service.setVersion("1.0.0"); service.setRef(genericService); service.setCluster("failfast"); int rpcTimeOut = key.rpcTimeOut(); if(rpcTimeOut != 0){ service.setTimeout(key.rpcTimeOut()); } service.setFilter("easyTransFilter"); if(applicationConfig != null) { service.setApplication(applicationConfig); } if(registryConfig != null) { service.setRegistry(registryConfig); } if(protocolConfig != null) { service.setProtocol(protocolConfig); } if(monitorConfig != null) { service.setMonitor(monitorConfig); } if(moduleConfig != null) { service.setModule(moduleConfig); } if(providerConfig != null) { service.setProvider(providerConfig); } if(customizationer != null) { customizationer.customDubboService(key,service); } service.export(); } }
Example 4
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 5
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 6
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 7
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example 8
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testAppendFilter() throws Exception { ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setApplication(new ApplicationConfig("provider")); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); try { service.export(); List<URL> urls = service.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { reference.get(); urls = reference.toUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { reference.destroy(); } } finally { service.unexport(); } }