org.apache.dubbo.config.ApplicationConfig Java Examples
The following examples show how to use
org.apache.dubbo.config.ApplicationConfig.
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: GenericImplProvider.java From dubbo-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { new EmbeddedZooKeeper(2181, false).start(); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("generic-impl-provider"); RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress(zookeeperAddress); GenericService helloService = new GenericImplOfHelloService(); ServiceConfig<GenericService> service = new ServiceConfig<>(); service.setApplication(applicationConfig); service.setRegistry(registryConfig); service.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService"); service.setRef(helloService); service.setGeneric("true"); service.export(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example #2
Source File: DirectServiceIT.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Test public void testGeneric() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("direct-consumer"); ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); reference.setVersion("1.0.0-daily"); reference.setGroup("test"); reference.setGeneric(true); reference.setApplication(application); reference.setInterface(DirectService.class.getName()); GenericService genericService = reference.get(); Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new Object[]{ "generic" }); String str = (String) obj; TestCase.assertTrue(str.startsWith("Hello generic")); }
Example #3
Source File: GenericCallConsumer.java From dubbo-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("generic-call-consumer"); RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("zookeeper://127.0.0.1:2181"); ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>(); referenceConfig.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService"); applicationConfig.setRegistry(registryConfig); referenceConfig.setApplication(applicationConfig); referenceConfig.setGeneric(true); referenceConfig.setAsync(true); referenceConfig.setTimeout(7000); genericService = referenceConfig.get(); invokeSayHello(); invokeSayHelloAsync(); invokeAsyncSayHelloAsync(); invokeAsyncSayHello(); // invokeSayHelloAsyncComplex(); asyncInvokeSayHelloAsyncComplex(); // invokeSayHelloAsyncGenericComplex(); asyncInvokeSayHelloAsyncGenericComplex(); }
Example #4
Source File: RelaxedDubboConfigBinderTest.java From dubbo-spring-boot-project with Apache License 2.0 | 6 votes |
@Test public void testBinder() { ApplicationConfig applicationConfig = new ApplicationConfig(); Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application"); dubboConfigBinder.bind(properties, true, true, applicationConfig); Assert.assertEquals("hello", applicationConfig.getName()); Assert.assertEquals("world", applicationConfig.getOwner()); RegistryConfig registryConfig = new RegistryConfig(); properties = getSubProperties(environment.getPropertySources(), "dubbo.registry"); dubboConfigBinder.bind(properties, true, true, registryConfig); Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); ProtocolConfig protocolConfig = new ProtocolConfig(); properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol"); dubboConfigBinder.bind(properties, true, true, protocolConfig); Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); }
Example #5
Source File: DubboConfigsMetadata.java From dubbo-spring-boot-project with Apache License 2.0 | 6 votes |
public Map<String, Map<String, Map<String, Object>>> configs() { Map<String, Map<String, Map<String, Object>>> configsMap = new LinkedHashMap<>(); addDubboConfigBeans(ApplicationConfig.class, configsMap); addDubboConfigBeans(ConsumerConfig.class, configsMap); addDubboConfigBeans(MethodConfig.class, configsMap); addDubboConfigBeans(ModuleConfig.class, configsMap); addDubboConfigBeans(MonitorConfig.class, configsMap); addDubboConfigBeans(ProtocolConfig.class, configsMap); addDubboConfigBeans(ProviderConfig.class, configsMap); addDubboConfigBeans(ReferenceConfig.class, configsMap); addDubboConfigBeans(RegistryConfig.class, configsMap); addDubboConfigBeans(ServiceConfig.class, configsMap); return configsMap; }
Example #6
Source File: MetricsServiceIT.java From dubbo-samples with Apache License 2.0 | 6 votes |
@Test public void test() throws Exception { for (int i = 0; i < 10; i++) { System.out.println("result: " + demoService.sayHello("dubbo")); } ReferenceConfig<MetricsService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("metrics-demo-consumer")); reference.setUrl("dubbo://" + providerHost + ":" + providerPort + "/" + MetricsService.class.getName()); reference.setInterface(MetricsService.class); MetricsService service = reference.get(); String result = service.getMetricsByGroup("dubbo"); JSONArray metrics = (JSONArray) JSON.parse(result); Assert.assertFalse(metrics.isEmpty()); for (int i = 0; i < metrics.size(); i++) { String metric = (String) ((JSONObject) metrics.get(1)).get("metric"); Assert.assertTrue(metric.startsWith("dubbo.provider") || metric.startsWith("threadPool")); } }
Example #7
Source File: BinderDubboConfigBinderTest.java From dubbo-spring-boot-project with Apache License 2.0 | 6 votes |
@Test public void testBinder() { ApplicationConfig applicationConfig = new ApplicationConfig(); Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application"); dubboConfigBinder.bind(properties, true, true, applicationConfig); Assert.assertEquals("hello", applicationConfig.getName()); Assert.assertEquals("world", applicationConfig.getOwner()); RegistryConfig registryConfig = new RegistryConfig(); properties = getSubProperties(environment.getPropertySources(), "dubbo.registry"); dubboConfigBinder.bind(properties, true, true, registryConfig); Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); ProtocolConfig protocolConfig = new ProtocolConfig(); properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol"); dubboConfigBinder.bind(properties, true, true, protocolConfig); Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); }
Example #8
Source File: GenericServiceTest.java From jmeter-plugins-for-apache-dubbo with Apache License 2.0 | 6 votes |
@Test public void testAttachment() { ApplicationConfig application = new ApplicationConfig(); application.setName("api-generic-consumer"); ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); reference.setUrl("dubbo://192.168.56.1:20880/org.apache.dubbo.samples.basic.api.DemoService"); reference.setVersion("1.0.0"); reference.setTimeout(2000); reference.setGeneric(true); reference.setApplication(application); reference.setInterface("com.jiuyescm.account.api.IUserService"); GenericService genericService = reference.get(); RpcContext.getContext().setAttachment("test.ningyu","this is attachmentValue"); Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new String[]{"ningyu"}); String json = JsonUtils.toJson(obj); System.out.println(json); }
Example #9
Source File: GenericServiceTest.java From jmeter-plugins-for-apache-dubbo with Apache License 2.0 | 6 votes |
@Test public void test() { ApplicationConfig application = new ApplicationConfig(); application.setName("api-generic-consumer"); ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); reference.setUrl("dubbo://192.168.56.1:20880/org.apache.dubbo.samples.basic.api.DemoService"); reference.setVersion("1.0.0"); reference.setTimeout(2000); reference.setGeneric(true); reference.setApplication(application); reference.setInterface("com.jiuyescm.account.api.IUserService"); GenericService genericService = reference.get(); Object obj = genericService.$invoke("getUserById", new String[]{Long.class.getName()}, new Long[]{1L}); String json = JsonUtils.toJson(obj); System.out.println(json); }
Example #10
Source File: TestServer.java From brave with Apache License 2.0 | 6 votes |
TestServer(Propagation.Factory propagationFactory, ApplicationConfig application) { extractor = propagationFactory.get().extractor(Map::get); linkLocalIp = Platform.get().linkLocalIp(); if (linkLocalIp != null) { // avoid dubbo's logic which might pick docker ip System.setProperty(CommonConstants.DUBBO_IP_TO_BIND, linkLocalIp); System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp); } service = new ServiceConfig<>(); service.setApplication(application); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setProtocol(new ProtocolConfig("dubbo", PickUnusedPort.get())); service.setInterface(GreeterService.class); service.setRef((method, parameterTypes, args) -> { requestQueue.add(extractor.extract(RpcContext.getContext().getAttachments())); return args[0]; }); }
Example #11
Source File: Application.java From dubbo-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { ServiceConfig<UserService> service = new ServiceConfig<>(); service.setInterface(UserService.class); service.setRef(new UserServiceImpl()); ProtocolConfig protocolConfig = new ProtocolConfig("rest"); protocolConfig.setPort(8090); DubboBootstrap bootstrap = DubboBootstrap.getInstance(); bootstrap.application(new ApplicationConfig("dubbo-provider-for-sc")) .registry(new RegistryConfig("consul://127.0.0.1:8500?registry-type=service")) .protocol(protocolConfig) .service(service) .start() .await(); }
Example #12
Source File: SslBasicConsumer.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { SslConfig sslConfig = new SslConfig(); if (args.length > 0) { if (args.length != 1 && args.length != 3) { System.out.println( "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " + "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS."); System.exit(0); } switch (args.length) { case 1: sslConfig.setClientTrustCertCollectionPath(args[0]); break; case 3: sslConfig.setClientTrustCertCollectionPath(args[0]); sslConfig.setClientKeyCertChainPath(args[1]); sslConfig.setClientPrivateKeyPath(args[2]); } } DubboBootstrap bootstrap = DubboBootstrap.getInstance() .application(new ApplicationConfig("first-dubbo-consumer")) .registry(new RegistryConfig("zookeeper://127.0.0.1:2181")) .ssl(sslConfig); ReferenceConfig<DemoService> reference = new ReferenceConfig<>(); reference.setInterface(DemoService.class); bootstrap.reference(reference); bootstrap.start(); DemoService service = bootstrap.getCache().get(reference); String message = service.sayHello("dubbo"); System.out.println(message); }
Example #13
Source File: HelloServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("generic-call-consumer"); RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("zookeeper://" + zookeeperHost + ":2181"); ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>(); referenceConfig.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService"); applicationConfig.setRegistry(registryConfig); referenceConfig.setApplication(applicationConfig); referenceConfig.setGeneric(true); referenceConfig.setAsync(true); referenceConfig.setTimeout(7000); genericService = referenceConfig.get(); }
Example #14
Source File: MonitorServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { ServiceConfig<MonitorService> service = new ServiceConfig<>(); // FIXME: has to set application name to "demo-consumer" service.setApplication(new ApplicationConfig("demo-consumer")); service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); // MonitorConfig monitorConfig = new MonitorConfig(); // monitorConfig.setProtocol("registry"); // monitorConfig.setInterval("100"); // service.setMonitor(monitorConfig); service.setInterface(MonitorService.class); service.setFilter("-monitor"); service.setRef(new MonitorServiceImpl()); service.export(); }
Example #15
Source File: GreetingServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void test() { ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("first-dubbo-consumer")); reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); reference.setInterface(GreetingsService.class); GreetingsService service = reference.get(); String message = service.sayHi("dubbo"); TestCase.assertEquals(message, "hi, dubbo"); }
Example #16
Source File: MonitorServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { for (int i = 0; i < 10; i++) { demoService.sayHello("world"); Thread.sleep(50); } ReferenceConfig<MonitorService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("demo-consumer")); reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); reference.setInterface(MonitorService.class); reference.setFilter("-monitor"); MonitorService service = reference.get(); List<URL> stats = service.lookup(null); boolean countProvider = false; boolean countConsumer = false; for (URL stat : stats) { Assert.assertEquals("count", stat.getProtocol()); Assert.assertEquals("org.apache.dubbo.samples.monitor.api.DemoService/sayHello", stat.getPath()); if (stat.getParameter("application").equals("demo-provider")) { countProvider = true; } if (stat.getParameter("application").equals("demo-consumer")) { countConsumer = true; } System.out.println(stat); } Assert.assertTrue(countConsumer && countProvider); }
Example #17
Source File: Application.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ServiceConfig<GreetingsService> service = new ServiceConfig<>(); service.setApplication(new ApplicationConfig("first-dubbo-provider")); service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); service.setInterface(GreetingsService.class); service.setRef(new GreetingsServiceImpl()); service.export(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example #18
Source File: Application.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("first-dubbo-consumer")); reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); reference.setInterface(GreetingsService.class); GreetingsService service = reference.get(); String message = service.sayHi("dubbo"); System.out.println(message); }
Example #19
Source File: GreetingsServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { ConfigCenterConfig configCenter = new ConfigCenterConfig(); ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer"); configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181"); ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>(); reference.setApplication(applicationConfig); reference.setConfigCenter(configCenter); reference.setInterface(GreetingsService.class); GreetingsService greetingsService = reference.get(); String message = greetingsService.sayHi("dubbo"); Assert.assertEquals("hi, dubbo", message); }
Example #20
Source File: DemoServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { ConfigCenterConfig configCenter = new ConfigCenterConfig(); ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-consumer"); configCenter.setAddress("zookeeper://" + zookeeperHost + ":2181"); ReferenceConfig<DemoService> reference = new ReferenceConfig<>(); reference.setApplication(applicationConfig); reference.setConfigCenter(configCenter); reference.setInterface(DemoService.class); DemoService demoService = reference.get(); Assert.assertEquals("Hello, you!", demoService.sayHello()); }
Example #21
Source File: ChronusAutoConfiguration.java From chronus with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean({ApplicationConfig.class, RegistryConfig.class}) public ChronusSdkProcessor chronusSdkFacade() { ChronusSdkProcessor chronusClientFacade = new AbstractSdkService(){}; ServiceConfig<ChronusSdkProcessor> serviceConfig = new ServiceConfig<>(); serviceConfig.setApplication(applicationConfig); serviceConfig.setRegistry(registryConfig); serviceConfig.setInterface(ChronusSdkProcessor.class); serviceConfig.setRef(chronusClientFacade); serviceConfig.setPath("/" + applicationConfig.getName() + "/" + ChronusSdkProcessor.class.getName()); //serviceConfig.setGroup(applicationConfig.getName()); serviceConfig.export(); return chronusClientFacade; }
Example #22
Source File: DirectServiceIT.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Test public void testApi() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("direct-consumer"); ReferenceConfig<DirectService> reference = new ReferenceConfig<>(); reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); reference.setVersion("1.0.0-daily"); reference.setGroup("test"); reference.setApplication(application); reference.setInterface(DirectService.class.getName()); DirectService service = reference.get(); String result = service.sayHello("api"); TestCase.assertTrue(result.startsWith("Hello api")); }
Example #23
Source File: SslBasicConsumer.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { SslConfig sslConfig = new SslConfig(); if (args.length > 0) { if (args.length != 1 && args.length != 3) { System.out.println( "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " + "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS."); System.exit(0); } switch (args.length) { case 1: sslConfig.setClientTrustCertCollectionPath(args[0]); break; case 3: sslConfig.setClientTrustCertCollectionPath(args[0]); sslConfig.setClientKeyCertChainPath(args[1]); sslConfig.setClientPrivateKeyPath(args[2]); } } DubboBootstrap bootstrap = DubboBootstrap.getInstance() .application(new ApplicationConfig("first-dubbo-consumer")) .registry(new RegistryConfig("zookeeper://127.0.0.1:2181")) .ssl(sslConfig); ReferenceConfig<IGreeter> reference = new ReferenceConfig<>(); reference.setInterface(IGreeter.class); bootstrap.reference(reference); bootstrap.start(); IGreeter service = bootstrap.getCache().get(reference); HelloReply helloReply = service.sayHello(HelloRequest.newBuilder().setName("dubbo").build()); System.out.println(helloReply.getMessage()); }
Example #24
Source File: Provider.java From rpcx-benchmark with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>(); service.setApplication(new ApplicationConfig("dubbo-demo-api-provider")); String zk = "zookeeper://127.0.0.1:2181"; if (args.length > 0) { zk = args[0]; } service.setRegistry(new RegistryConfig(zk)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.export(); Thread.sleep(24 * 3600 * 1000); }
Example #25
Source File: Consumer.java From rpcx-benchmark with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ReferenceConfig<DemoService> reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer")); String zk = "zookeeper://127.0.0.1:2181"; if (args.length > 2) { zk = args[2]; } reference.setRegistry(new RegistryConfig(zk)); reference.setInterface(DemoService.class); reference.setTimeout(10000); DemoService service = reference.get(); DemoAction demoAction = new DemoAction(); demoAction.setDemoService(service); if (args.length > 0) { demoAction.threads = Integer.parseInt(args[0]); } if (args.length > 1) { demoAction.count = Integer.parseInt(args[1]); } demoAction.warmup(); demoAction.start(); }
Example #26
Source File: DubboConfigBeanDefinitionConflictProcessor.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
private boolean isConfiguredApplicationConfigBeanName(String beanName) { boolean removed = BeanFactoryUtils.isGeneratedBeanName(beanName) // Dubbo ApplicationConfig id as bean name || Objects.equals(beanName, environment.getProperty("dubbo.application.id")); if (removed) { if (logger.isWarnEnabled()) { logger.warn("The {} bean [ name : {} ] has been removed!", ApplicationConfig.class.getSimpleName(), beanName); } } return removed; }
Example #27
Source File: DubboConfigBeanDefinitionConflictProcessor.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
/** * Resolve the unique {@link ApplicationConfig} Bean * * @param registry {@link BeanDefinitionRegistry} instance * @param beanFactory {@link ConfigurableListableBeanFactory} instance * @see EnableDubboConfig */ private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ConfigurableListableBeanFactory beanFactory) { this.environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class); String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class); if (beansNames.length < 2) { // If the number of ApplicationConfig beans is less than two, return immediately. return; } // Remove ApplicationConfig Beans that are configured by "dubbo.application.*" Stream.of(beansNames) .filter(this::isConfiguredApplicationConfigBeanName) .forEach(registry::removeBeanDefinition); beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class); if (beansNames.length > 1) { throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames) .map(registry::getBeanDefinition) .collect(Collectors.toList())) ); } }
Example #28
Source File: DubboConfigBeanDefinitionConflictApplicationListener.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
private boolean isConfiguredApplicationConfigBeanName(Environment environment, String beanName) { boolean removed = BeanFactoryUtils.isGeneratedBeanName(beanName) // Dubbo ApplicationConfig id as bean name || Objects.equals(beanName, environment.getProperty("dubbo.application.id")); if (removed) { if (logger.isDebugEnabled()) { logger.debug("The {} bean [ name : {} ] has been removed!", ApplicationConfig.class.getSimpleName(), beanName); } } return removed; }
Example #29
Source File: DubboConfigBeanDefinitionConflictApplicationListener.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
/** * Resolve the unique {@link ApplicationConfig} Bean * @param registry {@link BeanDefinitionRegistry} instance * @param beanFactory {@link ConfigurableListableBeanFactory} instance * @see EnableDubboConfig */ private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ListableBeanFactory beanFactory) { String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class); if (beansNames.length < 2) { // If the number of ApplicationConfig beans is less than two, return immediately. return; } Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class); // Remove ApplicationConfig Beans that are configured by "dubbo.application.*" Stream.of(beansNames) .filter(beansName -> isConfiguredApplicationConfigBeanName(environment, beansName)) .forEach(registry::removeBeanDefinition); beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class); if (beansNames.length > 1) { throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames) .map(registry::getBeanDefinition) .collect(Collectors.toList())) ); } }
Example #30
Source File: GenericServiceTest.java From jmeter-plugins-for-apache-dubbo with Apache License 2.0 | 5 votes |
@Test public void testZk() { for(int i=0;i<5;i++) { ApplicationConfig application = new ApplicationConfig(); application.setName("api-generic-consumer"); ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); reference.setVersion("1.0.0"); RegistryConfig registry = new RegistryConfig(); registry.setProtocol(Constants.REGISTRY_ZOOKEEPER); registry.setAddress("192.168.0.44:2181,192.168.0.44:2182,192.168.0.44:2183"); registry.setTimeout(10000); reference.setRegistry(registry); ConfigCenterConfig cc = new ConfigCenterConfig(); cc.setAddress("192.168.0.58:2181,192.168.0.59:2181,192.168.0.60:2181"); cc.setProtocol(Constants.REGISTRY_ZOOKEEPER); cc.setTimeout(Long.valueOf("10000")); cc.setGroup(""); cc.setNamespace(""); reference.setConfigCenter(cc); reference.setTimeout(2000); reference.setGeneric(true); reference.setApplication(application); reference.setInterface("com.jiuyescm.account.api.IUserService"); GenericService genericService = reference.get(); Object obj = genericService.$invoke("getUserById", new String[]{Long.class.getName()}, new Long[]{1L}); String json = JsonUtils.toJson(obj); System.out.println(json); } }