Dubbo Cloud Native (#4764)
* Polish apache/dubbo#4542 : [Enhancement] Adapt the Java standard Event/Listener mechanism * Polish apache/dubbo#4541 : [Feature] Add local File System DynamicConfigurationFactory‘s extension * Polish apache#4541 : Bugfix * Polish apache/dubbo#4541 : Optimization * Polish apache/dubbo#4541 : Add the compatibility for PollingWatchService on the some platforms * Polish apache/dubbo#4541 : Add delay publish without ThreadPoolExecutor * Polish apache/dubbo#4541 : Refactor the extension name * Polish apache/dubbo#4541 : Add remove ops * Polish apache/dubbo#4541 : Add testable constructor * Polish apache/dubbo#4541 : Add getConfigGroups method * Polish apache/dubbo#4610 : [Refactor] Refactor the bootstrap module * Polish apache/dubbo#4541 : Fix the nulling URL issue * Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager * Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager * Polish apache/dubbo#4622 : Support multiple configcenters * Polish apache/dubbo#4671 : ServiceNameMapping will not map the group, version and protocol * update referenceCount log (#4683) Add comments to support multiple shared connections * Polish /apache/dubbo#4687 : Remove the duplicated test code in dubbo-config-spring (#4688) * #4685 修改代码if判断false问题 if (hasException == false)修改成if (!hasException) (#4695) * Fixed Service annotation method parameters are not in effect (#4598) * keep demo simple, and switch to use zookeeper as registry center (#4705) * keep demo simple, and switch to use zookeeper as registry center * remove comment * @Reference auto-wires the instance of generic interface #4594 (#4677) * try to shorten maven output to make travis build pass (#4710) * use CountDownLatch to check zk registry if establish connection (#4589) * Minor change * Rename the extension name of WritableMetadataService * Polish apache/dubbo#4759 : [Refactor] Change the signature of methods of MetadataService #4759 * Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native # Conflicts: # dubbo-all/pom.xml # dubbo-bom/pom.xml # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java # dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java # dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java # dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java # dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java # dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java # dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java # dubbo-metadata/pom.xml # dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java # dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java # dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java # dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java * Polish apache/dubbo#3984 : Add the implementation of Page<ServiceInstance> getInstances(String serviceName, int offset, int pageSize, boolean healthyOnly) * Code merge
This commit is contained in:
parent
df34800184
commit
e7ce16d992
|
|
@ -12,7 +12,7 @@ cache:
|
|||
install: true
|
||||
|
||||
script:
|
||||
- travis_wait 30 ./mvnw clean install -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true
|
||||
- travis_wait 30 ./mvnw --quiet clean install -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>dubbo-bom</artifactId>
|
||||
|
|
|
|||
|
|
@ -26,14 +26,7 @@
|
|||
|
||||
<!-- Test dependencies -->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter-zookeeper</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Zookeeper dependencies for testing -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-zookeeper</artifactId>
|
||||
|
|
@ -48,29 +41,13 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Zookeeper dependencies for testing -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-etcd3</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<!-- <scope>test</scope>-->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metadata-report-etcd</artifactId>
|
||||
<artifactId>dubbo-configcenter-zookeeper</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter-etcd</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Nacos dependencies for testing -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
|
|
@ -113,17 +90,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.google.guava</groupId>-->
|
||||
<!-- <artifactId>guava</artifactId>-->
|
||||
<!-- <version>20.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
@ -57,7 +57,6 @@ import org.apache.dubbo.registry.support.ServiceOrientedRegistry;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -77,7 +76,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
|||
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
|
||||
import static org.apache.dubbo.config.context.ConfigManager.getInstance;
|
||||
import static org.apache.dubbo.registry.support.AbstractRegistryFactory.getRegistries;
|
||||
import static org.apache.dubbo.remoting.Constants.CLIENT_KEY;
|
||||
|
||||
/**
|
||||
* The bootstrap class of Dubbo
|
||||
|
|
@ -114,19 +112,14 @@ public class DubboBootstrap {
|
|||
|
||||
private final ConfigManager configManager = getInstance();
|
||||
|
||||
/**
|
||||
* Is provider or not
|
||||
*/
|
||||
private boolean isProvider;
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private boolean started = false;
|
||||
private volatile boolean started = false;
|
||||
|
||||
/**
|
||||
* Only Provider Register
|
||||
*/
|
||||
private boolean onlyRegisterProvider = false;
|
||||
private volatile boolean onlyRegisterProvider = false;
|
||||
|
||||
private ServiceInstance serviceInstance;
|
||||
|
||||
|
|
@ -155,6 +148,7 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
// {@link ApplicationConfig} correlative methods
|
||||
|
||||
/**
|
||||
|
|
@ -193,6 +187,7 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
// {@link RegistryConfig} correlative methods
|
||||
|
||||
/**
|
||||
|
|
@ -240,8 +235,8 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
// {@link ProtocolConfig} correlative methods
|
||||
|
||||
// {@link ProtocolConfig} correlative methods
|
||||
public DubboBootstrap protocol(Consumer<ProtocolBuilder> consumerBuilder) {
|
||||
return protocol(DEFAULT_PROTOCOL_ID, consumerBuilder);
|
||||
}
|
||||
|
|
@ -261,8 +256,8 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
// {@link ServiceConfig} correlative methods
|
||||
|
||||
// {@link ServiceConfig} correlative methods
|
||||
public <S> DubboBootstrap service(Consumer<ServiceBuilder<S>> consumerBuilder) {
|
||||
return service(DEFAULT_SERVICE_ID, consumerBuilder);
|
||||
}
|
||||
|
|
@ -278,8 +273,8 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
// {@link Reference} correlative methods
|
||||
|
||||
// {@link Reference} correlative methods
|
||||
public <S> DubboBootstrap reference(Consumer<ReferenceBuilder<S>> consumerBuilder) {
|
||||
return reference(DEFAULT_REFERENCE_ID, consumerBuilder);
|
||||
}
|
||||
|
|
@ -295,8 +290,8 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
// {@link ProviderConfig} correlative methods
|
||||
|
||||
// {@link ProviderConfig} correlative methods
|
||||
public DubboBootstrap provider(Consumer<ProviderBuilder> builderConsumer) {
|
||||
return provider(DEFAULT_PROVIDER_ID, builderConsumer);
|
||||
}
|
||||
|
|
@ -316,8 +311,8 @@ public class DubboBootstrap {
|
|||
return this;
|
||||
}
|
||||
|
||||
// {@link ConsumerConfig} correlative methods
|
||||
|
||||
// {@link ConsumerConfig} correlative methods
|
||||
public DubboBootstrap consumer(Consumer<ConsumerBuilder> builderConsumer) {
|
||||
return consumer(DEFAULT_CONSUMER_ID, builderConsumer);
|
||||
}
|
||||
|
|
@ -338,6 +333,7 @@ public class DubboBootstrap {
|
|||
}
|
||||
|
||||
// {@link ConfigCenterConfig} correlative methods
|
||||
|
||||
public DubboBootstrap configCenter(ConfigCenterConfig configCenterConfig) {
|
||||
return configCenter(asList(configCenterConfig));
|
||||
}
|
||||
|
|
@ -424,13 +420,8 @@ public class DubboBootstrap {
|
|||
String id = "config-center-" + protocol + "-" + registryConfig.getPort();
|
||||
ConfigCenterConfig cc = new ConfigCenterConfig();
|
||||
cc.setId(id);
|
||||
cc.setParameters(registryConfig.getParameters() == null ?
|
||||
new HashMap<>() :
|
||||
new HashMap<>(registryConfig.getParameters()));
|
||||
cc.getParameters().put(CLIENT_KEY,registryConfig.getClient());
|
||||
cc.setProtocol(registryConfig.getProtocol());
|
||||
cc.setProtocol(protocol);
|
||||
cc.setAddress(registryConfig.getAddress());
|
||||
cc.setNamespace(registryConfig.getGroup());
|
||||
cc.setHighestPriority(false);
|
||||
configManager.addConfigCenter(cc);
|
||||
});
|
||||
|
|
@ -463,7 +454,6 @@ public class DubboBootstrap {
|
|||
/**
|
||||
* export {@link MetadataService}
|
||||
*/
|
||||
// TODO, only export to default registry?
|
||||
List<URL> exportedURLs = exportMetadataService(
|
||||
configManager.getApplication().orElseThrow(() -> new IllegalStateException("ApplicationConfig cannot be null")),
|
||||
configManager.getRegistries(),
|
||||
|
|
@ -541,6 +531,7 @@ public class DubboBootstrap {
|
|||
|
||||
|
||||
/* serve for builder apis, begin */
|
||||
|
||||
private ApplicationBuilder createApplicationBuilder(String name) {
|
||||
return new ApplicationBuilder().name(name);
|
||||
}
|
||||
|
|
@ -569,8 +560,8 @@ public class DubboBootstrap {
|
|||
return new ConsumerBuilder().id(id);
|
||||
}
|
||||
|
||||
/* serve for builder apis, end */
|
||||
|
||||
/* serve for builder apis, end */
|
||||
private void startMetadataReport() {
|
||||
ApplicationConfig applicationConfig = configManager.getApplication().orElseThrow(() -> new IllegalStateException("There's no ApplicationConfig specified."));
|
||||
|
||||
|
|
@ -612,15 +603,14 @@ public class DubboBootstrap {
|
|||
return null;
|
||||
}
|
||||
DynamicConfiguration dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl());
|
||||
String configContent = dynamicConfiguration.getProperties(configCenter.getConfigFile(), configCenter.getGroup());
|
||||
String configContent = dynamicConfiguration.getRule(configCenter.getConfigFile(), configCenter.getGroup());
|
||||
|
||||
String appGroup = configManager.getApplication().orElse(new ApplicationConfig()).getName();
|
||||
String appConfigContent = null;
|
||||
if (isNotEmpty(appGroup)) {
|
||||
appConfigContent = dynamicConfiguration.getProperties
|
||||
(isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(),
|
||||
appGroup
|
||||
);
|
||||
appConfigContent = dynamicConfiguration.getConfig(isNotEmpty(configCenter.getAppConfigFile()) ?
|
||||
configCenter.getAppConfigFile() : configCenter.getConfigFile(), appGroup
|
||||
);
|
||||
}
|
||||
try {
|
||||
Environment.getInstance().setConfigCenterFirst(configCenter.isHighestPriority());
|
||||
|
|
@ -663,6 +653,10 @@ public class DubboBootstrap {
|
|||
serviceConfig.export();
|
||||
}
|
||||
|
||||
public boolean isOnlyRegisterProvider() {
|
||||
return onlyRegisterProvider;
|
||||
}
|
||||
|
||||
private void registerServiceInstance(List<URL> exportedURLs) {
|
||||
|
||||
exportedURLs
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package org.apache.dubbo.bootstrap;
|
|||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.context.ConfigManager;
|
||||
|
||||
|
||||
/**
|
||||
* Dubbo Provider Bootstrap
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ public class DubboServiceProviderBootstrap {
|
|||
.registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
|
||||
// Nacos
|
||||
.registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
|
||||
// .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry-type=service").build())
|
||||
.protocol(builder -> builder.port(-1).name("dubbo"))
|
||||
.service(builder -> builder.id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl()))
|
||||
.start()
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-cluster</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ public abstract class ListenableRouter extends AbstractRouter implements Configu
|
|||
}
|
||||
String routerKey = ruleKey + RULE_SUFFIX;
|
||||
configuration.addListener(routerKey, this);
|
||||
String rule = configuration.getRule(routerKey, DynamicConfiguration.DEFAULT_GROUP);
|
||||
String rule = configuration.getConfig(routerKey, DynamicConfiguration.DEFAULT_GROUP);
|
||||
if (StringUtils.isNotEmpty(rule)) {
|
||||
this.process(new ConfigChangeEvent(routerKey, rule));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
|
|||
String key = providerApplication + RULE_SUFFIX;
|
||||
configuration.addListener(key, this);
|
||||
application = providerApplication;
|
||||
String rawRule = configuration.getRule(key, DynamicConfiguration.DEFAULT_GROUP);
|
||||
String rawRule = configuration.getConfig(key, DynamicConfiguration.DEFAULT_GROUP);
|
||||
if (StringUtils.isNotEmpty(rawRule)) {
|
||||
this.process(new ConfigChangeEvent(key, rawRule));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ import org.apache.dubbo.rpc.support.MockInvoker;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
|
||||
import static org.apache.dubbo.rpc.Constants.MOCK_KEY;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
|
||||
|
||||
public class MockClusterInvoker<T> implements Invoker<T> {
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.cluster.router;
|
||||
|
||||
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRouterRule;
|
||||
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRuleParser;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRouterRule;
|
||||
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRuleParser;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_AVAILABLE_CHECK_KEY;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-common</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -127,6 +127,4 @@ public interface Configuration {
|
|||
|
||||
return cls.cast(obj);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.common.config.configcenter;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.concurrent.Executors.newFixedThreadPool;
|
||||
|
||||
/**
|
||||
* The abstract implementation of {@link DynamicConfiguration}
|
||||
*
|
||||
* @since 2.7.4
|
||||
*/
|
||||
public abstract class AbstractDynamicConfiguration implements DynamicConfiguration {
|
||||
|
||||
public static final String PARAM_NAME_PREFIX = "dubbo.config-center.";
|
||||
|
||||
public static final String THREAD_POOL_PREFIX_PARAM_NAME = PARAM_NAME_PREFIX + "thread-pool.prefix";
|
||||
|
||||
public static final String THREAD_POOL_SIZE_PARAM_NAME = PARAM_NAME_PREFIX + "thread-pool.size";
|
||||
|
||||
public static final String DEFAULT_THREAD_POOL_PREFIX = PARAM_NAME_PREFIX + "workers";
|
||||
|
||||
public static final String DEFAULT_THREAD_POOL_SIZE = "1";
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
/**
|
||||
* The thread pool for workers who executes the tasks
|
||||
*/
|
||||
private final ThreadPoolExecutor workersThreadPool;
|
||||
|
||||
public AbstractDynamicConfiguration(URL url) {
|
||||
this.workersThreadPool = initWorkersThreadPool(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(String key, String group, ConfigurationListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(String key, String group, ConfigurationListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
return execute(() -> doGetConfig(key, group), timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void close() throws Exception {
|
||||
try {
|
||||
doClose();
|
||||
} finally {
|
||||
doFinally();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of configuration in the specified key and group
|
||||
*
|
||||
* @param key the key
|
||||
* @param group the group
|
||||
* @return if found, return the content of configuration
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
protected abstract String doGetConfig(String key, String group) throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* Close the resources if necessary
|
||||
*
|
||||
* @throws Exception If met with some problems
|
||||
*/
|
||||
protected abstract void doClose() throws Exception;
|
||||
|
||||
/**
|
||||
* Executes the {@link Runnable} with the specified timeout
|
||||
*
|
||||
* @param task the {@link Runnable task}
|
||||
* @param timeout timeout in milliseconds
|
||||
*/
|
||||
protected final void execute(Runnable task, long timeout) {
|
||||
execute(() -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the {@link Callable} with the specified timeout
|
||||
*
|
||||
* @param task the {@link Callable task}
|
||||
* @param timeout timeout in milliseconds
|
||||
* @param <V> the type of computing result
|
||||
* @return the computing result
|
||||
*/
|
||||
protected final <V> V execute(Callable<V> task, long timeout) {
|
||||
V value = null;
|
||||
try {
|
||||
|
||||
if (timeout < 1) { // less or equal 0
|
||||
value = task.call();
|
||||
} else {
|
||||
Future<V> future = workersThreadPool.submit(task);
|
||||
value = future.get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void doFinally() {
|
||||
shutdownWorkersThreadPool();
|
||||
}
|
||||
|
||||
private void shutdownWorkersThreadPool() {
|
||||
if (!workersThreadPool.isShutdown()) {
|
||||
workersThreadPool.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
protected ThreadPoolExecutor initWorkersThreadPool(URL url) {
|
||||
int size = getThreadPoolSize(url);
|
||||
String name = getThreadPoolPrefixName(url);
|
||||
return (ThreadPoolExecutor) newFixedThreadPool(size, new NamedThreadFactory(name));
|
||||
}
|
||||
|
||||
protected static String getThreadPoolPrefixName(URL url) {
|
||||
return getParameter(url, THREAD_POOL_PREFIX_PARAM_NAME, DEFAULT_THREAD_POOL_PREFIX);
|
||||
}
|
||||
|
||||
protected static int getThreadPoolSize(URL url) {
|
||||
return Integer.parseInt(getParameter(url, THREAD_POOL_SIZE_PARAM_NAME, DEFAULT_THREAD_POOL_SIZE));
|
||||
}
|
||||
|
||||
protected static String getParameter(URL url, String name, String defaultValue) {
|
||||
if (url != null) {
|
||||
return url.getParameter(name, defaultValue);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,10 +21,11 @@ import org.apache.dubbo.common.config.Configuration;
|
|||
import org.apache.dubbo.common.config.Environment;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory.getDynamicConfigurationFactory;
|
||||
import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
|
||||
|
|
@ -33,12 +34,13 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad
|
|||
* Dynamic Configuration
|
||||
* <br/>
|
||||
* From the use scenario internally inside framework, there're mainly three kinds of methods:
|
||||
* <ul>
|
||||
* <li>1. getRule, get governance rules.</li>
|
||||
* <li>2. getProperties, get configuration file from Config Center at start up.</li>
|
||||
* <li>3. addListener/removeListener, add or remove listeners for governance rules or config items that need to watch.</li>
|
||||
* <li>4. getProperty, get a single config item.</li>
|
||||
* </ul>
|
||||
* <ol>
|
||||
* <li>{@link #getRule(String, String, long)}, get governance rules.</li>
|
||||
* <li>{@link #getProperties(String, String, long)}, get configuration file from Config Center at start up.</li>
|
||||
* <li>{@link #addListener(String, String, ConfigurationListener)}/ {@link #removeListener(String, String, ConfigurationListener)}
|
||||
* , add or remove listeners for governance rules or config items that need to watch.</li>
|
||||
* <li>{@link #getProperty(String, Object)}, get a single config item.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public interface DynamicConfiguration extends Configuration, AutoCloseable {
|
||||
|
||||
|
|
@ -86,12 +88,52 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
|
|||
*/
|
||||
void removeListener(String key, String group, ConfigurationListener listener);
|
||||
|
||||
/**
|
||||
* Get the configuration mapped to the given key and the given group
|
||||
*
|
||||
* @param key the key to represent a configuration
|
||||
* @param group the group where the key belongs to
|
||||
* @return target configuration mapped to the given key and the given group
|
||||
*/
|
||||
default String getConfig(String key, String group) {
|
||||
return getConfig(key, group, -1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration mapped to the given key and the given group. If the
|
||||
* configuration fails to fetch after timeout exceeds, IllegalStateException will be thrown.
|
||||
*
|
||||
* @param key the key to represent a configuration
|
||||
* @param group the group where the key belongs to
|
||||
* @param timeout timeout value for fetching the target config
|
||||
* @return target configuration mapped to the given key and the given group, IllegalStateException will be thrown
|
||||
* if timeout exceeds.
|
||||
*/
|
||||
String getConfig(String key, String group, long timeout) throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
|
||||
*/
|
||||
default String getProperties(String key, String group) throws IllegalStateException {
|
||||
return getProperties(key, group, -1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
|
||||
*
|
||||
* @revision 2.7.4
|
||||
*/
|
||||
default String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the governance rule mapped to the given key and the given group
|
||||
*
|
||||
* @param key the key to represent a configuration
|
||||
* @param group the group where the key belongs to
|
||||
* @return target configuration mapped to the given key and the given group
|
||||
* @since 2.7.3
|
||||
*/
|
||||
default String getRule(String key, String group) {
|
||||
return getRule(key, group, -1L);
|
||||
|
|
@ -106,22 +148,10 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
|
|||
* @param timeout timeout value for fetching the target config
|
||||
* @return target configuration mapped to the given key and the given group, IllegalStateException will be thrown
|
||||
* if timeout exceeds.
|
||||
* @since 2.7.3
|
||||
*/
|
||||
String getRule(String key, String group, long timeout) throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
|
||||
*/
|
||||
default String getProperties(String key, String group) throws IllegalStateException {
|
||||
return getProperties(key, group, -1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method are mostly used to get a compound config file, such as a complete dubbo.properties file.
|
||||
*/
|
||||
String getProperties(String key, String group, long timeout) throws IllegalStateException;
|
||||
|
||||
|
||||
/**
|
||||
* Publish Config mapped to the given key under the {@link #DEFAULT_GROUP default group}
|
||||
*
|
||||
|
|
@ -189,42 +219,42 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
|
|||
* Get the config keys by the specified group
|
||||
*
|
||||
* @param group the specified group
|
||||
* @return the read-only non-null {@link Set set} of config keys
|
||||
* @return the read-only non-null sorted {@link Set set} of config keys
|
||||
* @throws UnsupportedOperationException If the under layer does not support
|
||||
* @since 2.7.4
|
||||
*/
|
||||
default Set<String> getConfigKeys(String group) throws UnsupportedOperationException {
|
||||
default SortedSet<String> getConfigKeys(String group) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException("No support");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Map} with with config keys and contents value by the specified group
|
||||
* Get the {@link SortedMap} with with config keys and contents value by the specified group
|
||||
*
|
||||
* @param group the specified group
|
||||
* @return the read-only non-null {@link Map map}
|
||||
* @return the read-only non-null sorted {@link SortedMap map}
|
||||
* @throws UnsupportedOperationException If the under layer does not support
|
||||
* @since 2.7.4
|
||||
*/
|
||||
default Map<String, String> getConfigs(String group) throws UnsupportedOperationException {
|
||||
default SortedMap<String, String> getConfigs(String group) throws UnsupportedOperationException {
|
||||
return getConfigs(group, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Map} with with config keys and content value by the specified group
|
||||
* Get the {@link SortedMap} with with config keys and content value by the specified group
|
||||
*
|
||||
* @param group the specified group
|
||||
* @param timeout the millisecond for timeout
|
||||
* @return the read-only non-null {@link Map map}
|
||||
* @return the read-only non-null sorted {@link SortedMap map}
|
||||
* @throws UnsupportedOperationException If the under layer does not support
|
||||
* @throws IllegalStateException If timeout exceeds
|
||||
* @since 2.7.4
|
||||
*/
|
||||
default Map<String, String> getConfigs(String group, long timeout) throws UnsupportedOperationException,
|
||||
default SortedMap<String, String> getConfigs(String group, long timeout) throws UnsupportedOperationException,
|
||||
IllegalStateException {
|
||||
Map<String, String> configs = new LinkedHashMap<>();
|
||||
Set<String> configKeys = getConfigKeys(group);
|
||||
SortedMap<String, String> configs = new TreeMap<>();
|
||||
SortedSet<String> configKeys = getConfigKeys(group);
|
||||
configKeys.forEach(key -> configs.put(key, getString(key)));
|
||||
return Collections.unmodifiableMap(configs);
|
||||
return Collections.unmodifiableSortedMap(configs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -263,12 +293,12 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable {
|
|||
return factory.getDynamicConfiguration(connectionURL);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* The format is '{interfaceName}:[version]:[group]'
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static String getRuleKey(URL url) {
|
||||
static String getRuleKey(URL url) {
|
||||
return url.getColonSeparatedKey();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
|
|
@ -228,6 +231,12 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
File configFile = configFile(key, group);
|
||||
return getConfig(configFile, timeout);
|
||||
}
|
||||
|
||||
protected File configDirectory(String group) {
|
||||
String actualGroup = isBlank(group) ? DEFAULT_GROUP : group;
|
||||
return new File(rootDirectory, actualGroup);
|
||||
|
|
@ -341,8 +350,7 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration {
|
|||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
File configFile = configFile(key, group);
|
||||
return getConfig(configFile, timeout);
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
protected String getConfig(File configFile, long timeout) {
|
||||
|
|
@ -353,11 +361,6 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration {
|
|||
return file.exists() && file.canRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getRule(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
return null;
|
||||
|
|
@ -451,10 +454,10 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getConfigKeys(String group) {
|
||||
public SortedSet<String> getConfigKeys(String group) {
|
||||
return Stream.of(configDirectory(group).listFiles(File::isFile))
|
||||
.map(File::getName)
|
||||
.collect(Collectors.toSet());
|
||||
.collect(TreeSet::new, Set::add, Set::addAll);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -467,7 +470,7 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfigs(String group) throws UnsupportedOperationException {
|
||||
public SortedMap<String, String> getConfigs(String group) throws UnsupportedOperationException {
|
||||
return getConfigs(group, -1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ public class NopDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
// no-op
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
// no-op
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,11 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
|
|||
iterateListenerOperation(configuration -> configuration.removeListener(key, group, listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
return (String) iterateConfigOperation(configuration -> configuration.getConfig(key, group, timeout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
return (String) iterateConfigOperation(configuration -> configuration.getRule(key, group, timeout));
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ public interface CommonConstants {
|
|||
|
||||
String METADATA_KEY = "metadata";
|
||||
|
||||
String METADATA_DEFAULT = "local";
|
||||
String METADATA_DEFAULT = "default";
|
||||
|
||||
String METADATA_REMOTE = "remote";
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.extension;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Code generator for Adaptive class
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.apache.dubbo.common.bytecode;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class MixinTest {
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Inmemory configuration test.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package org.apache.dubbo.common.threadlocal;
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.common.model.person.FullAddress;
|
|||
import org.apache.dubbo.common.model.person.PersonInfo;
|
||||
import org.apache.dubbo.common.model.person.PersonStatus;
|
||||
import org.apache.dubbo.common.model.person.Phone;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -34,20 +35,20 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PojoUtilsTest {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-compatible</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@
|
|||
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo;
|
||||
|
||||
import org.apache.dubbo.rpc.AppResponse;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
|
||||
import com.alibaba.dubbo.remoting.RemotingException;
|
||||
import com.alibaba.dubbo.remoting.exchange.ResponseCallback;
|
||||
import com.alibaba.dubbo.remoting.exchange.ResponseFuture;
|
||||
import com.alibaba.dubbo.rpc.RpcException;
|
||||
|
||||
import org.apache.dubbo.rpc.AppResponse;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import static org.hamcrest.Matchers.hasKey;
|
|||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class MethodConfigTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class LegacyInvoker<T> implements Invoker<T> {
|
|||
|
||||
public Result invoke(Invocation invocation) throws RpcException {
|
||||
AppResponse result = new AppResponse();
|
||||
if (hasException == false) {
|
||||
if (!hasException) {
|
||||
result.setValue("alibaba");
|
||||
} else {
|
||||
result.setException(new RuntimeException("mocked exception"));
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@
|
|||
|
||||
package org.apache.dubbo.rpc;
|
||||
|
||||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcContextTest {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-config</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-config-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -435,5 +435,4 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
}
|
||||
parameters.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,13 +194,13 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
|
|||
if (!ReferenceConfig.this.destroyed) {
|
||||
logger.warn("ReferenceConfig(" + url + ") is not DESTROYED when FINALIZE");
|
||||
|
||||
/* don't destroy for now
|
||||
try {
|
||||
ReferenceConfig.this.destroy();
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Unexpected err when destroy invoker of ReferenceConfig(" + url + ") in finalize method!", t);
|
||||
}
|
||||
*/
|
||||
/* don't destroy for now
|
||||
try {
|
||||
ReferenceConfig.this.destroy();
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Unexpected err when destroy invoker of ReferenceConfig(" + url + ") in finalize method!", t);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -183,10 +183,12 @@ public class RegistryConfig extends AbstractConfig {
|
|||
if (address != null) {
|
||||
try {
|
||||
URL url = URL.valueOf(address);
|
||||
this.updateIdIfAbsent(url.getProtocol());
|
||||
this.updateProtocolIfAbsent(url.getProtocol());
|
||||
this.updatePortIfAbsent(url.getPort());
|
||||
this.updateParameters(url.getParameters());
|
||||
setUsername(url.getUsername());
|
||||
setPassword(url.getPassword());
|
||||
updateIdIfAbsent(url.getProtocol());
|
||||
updateProtocolIfAbsent(url.getProtocol());
|
||||
updatePortIfAbsent(url.getPort());
|
||||
setParameters(url.getParameters());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -767,7 +766,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
if (portToBind == null || portToBind == 0) {
|
||||
portToBind = defaultPort;
|
||||
}
|
||||
if (portToBind <= 0) {
|
||||
if (portToBind == null || portToBind <= 0) {
|
||||
portToBind = getRandomPort(name);
|
||||
if (portToBind == null || portToBind < 0) {
|
||||
portToBind = getAvailablePort(defaultPort);
|
||||
|
|
@ -1060,4 +1059,4 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
protected void dispatch(Event event) {
|
||||
eventDispatcher.dispatch(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -177,10 +177,10 @@ public class ReferenceConfigTest {
|
|||
Assertions.assertEquals(3, (int)((MethodConfig)referenceConfig.getMethods().get(0)).getActives());
|
||||
Assertions.assertEquals(5, (int)((MethodConfig)referenceConfig.getMethods().get(0)).getExecutes());
|
||||
Assertions.assertTrue(((MethodConfig) referenceConfig.getMethods().get(0)).isAsync());
|
||||
assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOninvoke(), "i");
|
||||
assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r");
|
||||
assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t");
|
||||
assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c");
|
||||
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOninvoke(), "i");
|
||||
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r");
|
||||
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t");
|
||||
Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.apache.dubbo.config.ProtocolConfig;
|
|||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.context.ConfigManager;
|
||||
import org.apache.dubbo.metadata.MetadataService;
|
||||
import org.apache.dubbo.metadata.MetadataServiceExporter;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -44,6 +43,7 @@ public class ConfigurableMetadataServiceExporterTest {
|
|||
@BeforeAll
|
||||
public static void init() {
|
||||
ConfigManager configManager = ConfigManager.getInstance();
|
||||
configManager.clear();
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig();
|
||||
applicationConfig.setName("test");
|
||||
configManager.setApplication(applicationConfig);
|
||||
|
|
@ -69,7 +69,8 @@ public class ConfigurableMetadataServiceExporterTest {
|
|||
|
||||
@Test
|
||||
public void testExportAndUnexport() {
|
||||
MetadataServiceExporter exporter = new ConfigurableMetadataServiceExporter();
|
||||
ConfigurableMetadataServiceExporter exporter = new ConfigurableMetadataServiceExporter();
|
||||
exporter.setApplicationConfig(ConfigManager.getInstance().getApplication().get());
|
||||
List<URL> urls = exporter.export();
|
||||
|
||||
assertEquals(1, urls.size());
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-config</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-config-spring</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,15 @@ class ReferenceBeanBuilder extends AnnotatedInterfaceConfigBeanBuilder<Reference
|
|||
}
|
||||
|
||||
private void configureInterface(AnnotationAttributes attributes, ReferenceBean referenceBean) {
|
||||
Boolean generic = getAttribute(attributes, "generic");
|
||||
if (generic != null && generic) {
|
||||
// it's a generic reference
|
||||
String interfaceClassName = getAttribute(attributes, "interfaceName");
|
||||
Assert.hasText(interfaceClassName,
|
||||
"@Reference interfaceName() must be present when reference a generic service!");
|
||||
referenceBean.setInterface(interfaceClassName);
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> serviceInterfaceClass = resolveServiceInterfaceClass(attributes, interfaceClass);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package org.apache.dubbo.config.spring.beans.factory.annotation;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.ArrayUtils;
|
||||
import org.apache.dubbo.config.MethodConfig;
|
||||
import org.apache.dubbo.config.annotation.Method;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.spring.ServiceBean;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
|
||||
|
|
@ -54,6 +56,7 @@ import org.springframework.util.StringUtils;
|
|||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -387,6 +390,11 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr
|
|||
builder.addPropertyValue("interface", interfaceClass.getName());
|
||||
// Convert parameters into map
|
||||
builder.addPropertyValue("parameters", convertParameters(serviceAnnotationAttributes.getStringArray("parameters")));
|
||||
// Add methods parameters
|
||||
List<MethodConfig> methodConfigs = convertMethodConfigs(serviceAnnotationAttributes.get("methods"));
|
||||
if (!methodConfigs.isEmpty()) {
|
||||
builder.addPropertyValue("methods", methodConfigs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link org.apache.dubbo.config.ProviderConfig} Bean reference
|
||||
|
|
@ -447,6 +455,12 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr
|
|||
|
||||
}
|
||||
|
||||
private List convertMethodConfigs(Object methodsAnnotation) {
|
||||
if (methodsAnnotation == null){
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
return MethodConfig.constructMethodConfig((Method[])methodsAnnotation);
|
||||
}
|
||||
|
||||
private ManagedList<RuntimeBeanReference> toRuntimeBeanReferences(String... beanNames) {
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,14 @@ public class AnnotationUtils {
|
|||
* @throws IllegalStateException if interface name was not found
|
||||
*/
|
||||
public static String resolveInterfaceName(AnnotationAttributes attributes, Class<?> defaultInterfaceClass) {
|
||||
Boolean generic = getAttribute(attributes, "generic");
|
||||
if (generic != null && generic) {
|
||||
// it's a generic reference
|
||||
String interfaceClassName = getAttribute(attributes, "interfaceName");
|
||||
Assert.hasText(interfaceClassName,
|
||||
"@Reference interfaceName() must be present when reference a generic service!");
|
||||
return interfaceClassName;
|
||||
}
|
||||
return resolveServiceInterfaceClass(attributes, defaultInterfaceClass).getName();
|
||||
}
|
||||
|
||||
|
|
@ -343,21 +351,9 @@ public class AnnotationUtils {
|
|||
if (ignoreDefaultValue && nullSafeEquals(attributeValue, getDefaultValue(annotation, attributeName))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.1
|
||||
* ignore annotation member
|
||||
*/
|
||||
if (attributeValue.getClass().isAnnotation()) {
|
||||
continue;
|
||||
}
|
||||
if (attributeValue.getClass().isArray() && attributeValue.getClass().getComponentType().isAnnotation()) {
|
||||
continue;
|
||||
}
|
||||
actualAttributes.put(attributeName, attributeValue);
|
||||
}
|
||||
|
||||
|
||||
return resolvePlaceholders(actualAttributes, propertyResolver, ignoreAttributeNames);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.beans.factory.annotation;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Method;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.spring.ReferenceBean;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
|
|
@ -47,14 +48,14 @@ import static org.junit.Assert.assertTrue;
|
|||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(
|
||||
classes = {
|
||||
ServiceAnnotationTestConfiguration.class,
|
||||
ReferenceAnnotationBeanPostProcessorTest.class
|
||||
})
|
||||
classes = {
|
||||
ServiceAnnotationTestConfiguration.class,
|
||||
ReferenceAnnotationBeanPostProcessorTest.class
|
||||
})
|
||||
@TestPropertySource(properties = {
|
||||
"packagesToScan = org.apache.dubbo.config.spring.context.annotation.provider",
|
||||
"consumer.version = ${demo.service.version}",
|
||||
"consumer.url = dubbo://127.0.0.1:12345?version=2.5.7",
|
||||
"packagesToScan = org.apache.dubbo.config.spring.context.annotation.provider",
|
||||
"consumer.version = ${demo.service.version}",
|
||||
"consumer.url = dubbo://127.0.0.1:12345?version=2.5.7",
|
||||
})
|
||||
public class ReferenceAnnotationBeanPostProcessorTest {
|
||||
|
||||
|
|
@ -79,7 +80,7 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
@Qualifier("helloServiceImpl")
|
||||
private HelloService helloServiceImpl;
|
||||
|
||||
@Reference(id = "helloService")
|
||||
@Reference(id = "helloService", methods = @Method(name = "sayName", timeout = 100))
|
||||
private HelloService helloService;
|
||||
|
||||
@Test
|
||||
|
|
@ -131,7 +132,7 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
public void testGetReferenceBeans() {
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
Collection<ReferenceBean<?>> referenceBeans = beanPostProcessor.getReferenceBeans();
|
||||
|
||||
|
|
@ -139,8 +140,6 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
|
||||
ReferenceBean<?> referenceBean = referenceBeans.iterator().next();
|
||||
|
||||
TestBean testBean = context.getBean(TestBean.class);
|
||||
|
||||
Assert.assertNotNull(referenceBean.get());
|
||||
|
||||
}
|
||||
|
|
@ -149,11 +148,10 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
public void testGetInjectedFieldReferenceBeanMap() {
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
|
||||
beanPostProcessor.getInjectedFieldReferenceBeanMap();
|
||||
beanPostProcessor.getInjectedFieldReferenceBeanMap();
|
||||
|
||||
Assert.assertEquals(2, referenceBeanMap.size());
|
||||
|
||||
|
|
@ -162,7 +160,7 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
InjectionMetadata.InjectedElement injectedElement = entry.getKey();
|
||||
|
||||
Assert.assertEquals("org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement",
|
||||
injectedElement.getClass().getName());
|
||||
injectedElement.getClass().getName());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -172,11 +170,10 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
public void testGetInjectedMethodReferenceBeanMap() {
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
|
||||
beanPostProcessor.getInjectedMethodReferenceBeanMap();
|
||||
beanPostProcessor.getInjectedMethodReferenceBeanMap();
|
||||
|
||||
Assert.assertEquals(2, referenceBeanMap.size());
|
||||
|
||||
|
|
@ -185,33 +182,32 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
InjectionMetadata.InjectedElement injectedElement = entry.getKey();
|
||||
|
||||
Assert.assertEquals("org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedMethodElement",
|
||||
injectedElement.getClass().getName());
|
||||
injectedElement.getClass().getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testModuleInfo() {
|
||||
//
|
||||
// ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
// ReferenceAnnotationBeanPostProcessor.class);
|
||||
//
|
||||
//
|
||||
// Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
|
||||
// beanPostProcessor.getInjectedMethodReferenceBeanMap();
|
||||
//
|
||||
// for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) {
|
||||
// ReferenceBean<?> referenceBean = entry.getValue();
|
||||
//
|
||||
// assertThat(referenceBean.getModule().getName(), is("defaultModule"));
|
||||
// assertThat(referenceBean.getMonitor(), not(nullValue()));
|
||||
// }
|
||||
// }
|
||||
// @Test
|
||||
// public void testModuleInfo() {
|
||||
//
|
||||
// ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
// ReferenceAnnotationBeanPostProcessor.class);
|
||||
//
|
||||
//
|
||||
// Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
|
||||
// beanPostProcessor.getInjectedMethodReferenceBeanMap();
|
||||
//
|
||||
// for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) {
|
||||
// ReferenceBean<?> referenceBean = entry.getValue();
|
||||
//
|
||||
// assertThat(referenceBean.getModule().getName(), is("defaultModule"));
|
||||
// assertThat(referenceBean.getMonitor(), not(nullValue()));
|
||||
// }
|
||||
// }
|
||||
|
||||
private static class AncestorBean {
|
||||
|
||||
|
||||
private DemoService demoServiceFromAncestor;
|
||||
|
||||
@Autowired
|
||||
|
|
@ -232,7 +228,6 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private static class ParentBean extends AncestorBean {
|
||||
|
||||
@Reference(version = "${consumer.version}", url = "${consumer.url}")
|
||||
|
|
@ -242,7 +237,6 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
return demoServiceFromParent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static class TestBean extends ParentBean {
|
||||
|
|
@ -265,4 +259,21 @@ public class ReferenceAnnotationBeanPostProcessorTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceBeansMethodAnnotation() {
|
||||
|
||||
ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
|
||||
ReferenceAnnotationBeanPostProcessor.class);
|
||||
|
||||
Collection<ReferenceBean<?>> referenceBeans = beanPostProcessor.getReferenceBeans();
|
||||
|
||||
Assert.assertEquals(2, referenceBeans.size());
|
||||
|
||||
ReferenceBean<?> referenceBean = referenceBeans.iterator().next();
|
||||
|
||||
if ("helloService".equals(referenceBean.getId())) {
|
||||
Assert.assertNotNull(referenceBean.getMethods());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -79,4 +79,17 @@ public class ServiceAnnotationBeanPostProcessorTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodAnnotation() {
|
||||
|
||||
Map<String, ServiceBean> serviceBeansMap = beanFactory.getBeansOfType(ServiceBean.class);
|
||||
|
||||
Assert.assertEquals(2, serviceBeansMap.size());
|
||||
|
||||
ServiceBean demoServiceBean = serviceBeansMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:2.5.7");
|
||||
|
||||
Assert.assertNotNull(demoServiceBean.getMethods());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,14 @@ import org.apache.dubbo.config.ProtocolConfig;
|
|||
import org.apache.dubbo.config.ProviderConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link EnableDubboConfig} Test
|
||||
*
|
||||
|
|
@ -92,6 +95,14 @@ public class EnableDubboConfigTest {
|
|||
ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName());
|
||||
|
||||
Map<String, ProtocolConfig> protocolConfigs = context.getBeansOfType(ProtocolConfig.class);
|
||||
|
||||
for (Map.Entry<String, ProtocolConfig> entry : protocolConfigs.entrySet()) {
|
||||
String beanName = entry.getKey();
|
||||
ProtocolConfig protocol = entry.getValue();
|
||||
Assert.assertEquals(beanName, protocol.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableDubboConfig
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.context.annotation.provider;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Method;
|
||||
import org.apache.dubbo.config.spring.api.Box;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
|
||||
|
|
@ -32,7 +33,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
version = "2.5.7",
|
||||
application = "${demo.service.application}",
|
||||
protocol = "${demo.service.protocol}",
|
||||
registry = "${demo.service.registry}"
|
||||
registry = "${demo.service.registry}",
|
||||
methods = @Method(timeout = 100,name = "sayName")
|
||||
)
|
||||
@Service
|
||||
@Transactional
|
||||
|
|
|
|||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScanRegistrar;
|
||||
import org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration;
|
||||
import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
|
||||
import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
|
||||
|
||||
/**
|
||||
* {@link DubboComponentScanRegistrar} Test
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
public class DubboComponentScanRegistrarTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
providerContext.register(ProviderConfiguration.class);
|
||||
|
||||
providerContext.refresh();
|
||||
|
||||
DemoService demoService = providerContext.getBean(DemoService.class);
|
||||
|
||||
String value = demoService.sayName("Mercy");
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", value);
|
||||
|
||||
Class<?> beanClass = AopUtils.getTargetClass(demoService);
|
||||
|
||||
// DemoServiceImpl with @Transactional
|
||||
Assertions.assertEquals(DemoServiceImpl.class, beanClass);
|
||||
|
||||
// Test @Transactional is present or not
|
||||
Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class));
|
||||
|
||||
AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
consumerContext.register(ConsumerConfiguration.class);
|
||||
|
||||
consumerContext.refresh();
|
||||
|
||||
ConsumerConfiguration consumerConfiguration = consumerContext.getBean(ConsumerConfiguration.class);
|
||||
|
||||
demoService = consumerConfiguration.getDemoService();
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", value);
|
||||
|
||||
ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class);
|
||||
|
||||
// From Child
|
||||
|
||||
demoService = child.getDemoServiceFromChild();
|
||||
|
||||
Assertions.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", value);
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", child.getDemoService().sayName("Mercy"));
|
||||
|
||||
// From Parent
|
||||
|
||||
demoService = child.getDemoServiceFromParent();
|
||||
|
||||
Assertions.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", value);
|
||||
|
||||
// From Ancestor
|
||||
|
||||
demoService = child.getDemoServiceFromAncestor();
|
||||
|
||||
Assertions.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assertions.assertEquals("Hello,Mercy", value);
|
||||
|
||||
providerContext.close();
|
||||
consumerContext.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* {@link DubboConfigBindingRegistrar}
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
public class DubboConfigBindingRegistrarTest {
|
||||
|
||||
@Test
|
||||
public void testRegisterBeanDefinitionsForSingle() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
context.register(TestApplicationConfig.class);
|
||||
|
||||
context.refresh();
|
||||
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterBeanDefinitionsForMultiple() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
context.register(TestMultipleApplicationConfig.class);
|
||||
|
||||
context.refresh();
|
||||
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
applicationConfig = context.getBean("applicationBean2", ApplicationConfig.class);
|
||||
|
||||
Assertions.assertEquals("dubbo-demo-application2", applicationConfig.getName());
|
||||
|
||||
applicationConfig = context.getBean("applicationBean3", ApplicationConfig.class);
|
||||
|
||||
Assertions.assertEquals("dubbo-demo-application3", applicationConfig.getName());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@EnableDubboConfigBinding(prefix = "${application.prefixes}", type = ApplicationConfig.class, multiple = true)
|
||||
@PropertySource("META-INF/config.properties")
|
||||
private static class TestMultipleApplicationConfig {
|
||||
|
||||
}
|
||||
|
||||
@EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class)
|
||||
@PropertySource("META-INF/config.properties")
|
||||
private static class TestApplicationConfig {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingsRegistrar;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBindings;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* {@link DubboConfigBindingsRegistrar} Test
|
||||
*
|
||||
* @since DubboConfigBindingsRegistrar
|
||||
*/
|
||||
public class DubboConfigBindingsRegistrarTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
context.register(TestConfig.class);
|
||||
|
||||
context.refresh();
|
||||
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
Assertions.assertEquals(2, context.getBeansOfType(ApplicationConfig.class).size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EnableDubboConfigBindings({
|
||||
@EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class),
|
||||
@EnableDubboConfigBinding(prefix = "dubbo.applications.applicationBean", type = ApplicationConfig.class)
|
||||
})
|
||||
@PropertySource("META-INF/config.properties")
|
||||
private static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ModuleConfig;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.io.support.ResourcePropertySource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* {@link DubboConfigConfiguration} Test
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
public class DubboConfigConfigurationTest {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void before() throws IOException {
|
||||
|
||||
context = new AnnotationConfigApplicationContext();
|
||||
ResourcePropertySource propertySource = new ResourcePropertySource("META-INF/config.properties");
|
||||
context.getEnvironment().getPropertySources().addFirst(propertySource);
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws IOException {
|
||||
|
||||
context.register(DubboConfigConfiguration.Single.class);
|
||||
context.refresh();
|
||||
|
||||
// application
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
// module
|
||||
ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName());
|
||||
|
||||
// registry
|
||||
RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
|
||||
Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());
|
||||
|
||||
// protocol
|
||||
ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
|
||||
Assertions.assertEquals("dubbo", protocolConfig.getName());
|
||||
Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiple() {
|
||||
|
||||
context.register(DubboConfigConfiguration.Multiple.class);
|
||||
context.refresh();
|
||||
|
||||
// application
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName());
|
||||
|
||||
ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ConsumerConfig;
|
||||
import org.apache.dubbo.config.ModuleConfig;
|
||||
import org.apache.dubbo.config.MonitorConfig;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.ProviderConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link EnableDubboConfig} Test
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
public class EnableDubboConfigTest {
|
||||
|
||||
@Test
|
||||
public void testSingle() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(TestConfig.class);
|
||||
context.refresh();
|
||||
|
||||
// application
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
// module
|
||||
ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName());
|
||||
|
||||
// registry
|
||||
RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
|
||||
Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());
|
||||
|
||||
// protocol
|
||||
ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
|
||||
Assertions.assertEquals("dubbo", protocolConfig.getName());
|
||||
Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
|
||||
|
||||
// monitor
|
||||
MonitorConfig monitorConfig = context.getBean(MonitorConfig.class);
|
||||
Assertions.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress());
|
||||
|
||||
// provider
|
||||
ProviderConfig providerConfig = context.getBean(ProviderConfig.class);
|
||||
Assertions.assertEquals("127.0.0.1", providerConfig.getHost());
|
||||
|
||||
|
||||
// consumer
|
||||
ConsumerConfig consumerConfig = context.getBean(ConsumerConfig.class);
|
||||
Assertions.assertEquals("netty", consumerConfig.getClient());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiple() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(TestMultipleConfig.class);
|
||||
context.refresh();
|
||||
|
||||
// application
|
||||
ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName());
|
||||
|
||||
ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName());
|
||||
|
||||
ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class);
|
||||
Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName());
|
||||
|
||||
Map<String, ProtocolConfig> protocolConfigs = context.getBeansOfType(ProtocolConfig.class);
|
||||
|
||||
for (Map.Entry<String, ProtocolConfig> entry : protocolConfigs.entrySet()) {
|
||||
String beanName = entry.getKey();
|
||||
ProtocolConfig protocol = entry.getValue();
|
||||
Assert.assertEquals(beanName, protocol.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableDubboConfig
|
||||
@PropertySource("META-INF/config.properties")
|
||||
private static class TestMultipleConfig {
|
||||
|
||||
}
|
||||
|
||||
@EnableDubboConfig(multiple = false)
|
||||
@PropertySource("META-INF/config.properties")
|
||||
private static class TestConfig {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation;
|
||||
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration;
|
||||
import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
|
||||
|
||||
/**
|
||||
* {@link EnableDubbo} Test
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {EnableDubboTest.class})
|
||||
@TestPropertySource(locations = "classpath:/META-INF/dubbb-provider.properties",
|
||||
properties = "demo.service.version = 2.5.7")
|
||||
@EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
|
||||
@ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
|
||||
@EnableTransactionManagement
|
||||
public class EnableDubboTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext providerContext;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
DemoService demoService = providerContext.getBean(DemoService.class);
|
||||
|
||||
String value = demoService.sayName("Mercy");
|
||||
|
||||
Assert.assertEquals("Hello,Mercy", value);
|
||||
|
||||
Class<?> beanClass = AopUtils.getTargetClass(demoService);
|
||||
|
||||
// DemoServiceImpl with @Transactional
|
||||
Assert.assertEquals(DemoServiceImpl.class, beanClass);
|
||||
|
||||
// Test @Transactional is present or not
|
||||
Assert.assertNotNull(findAnnotation(beanClass, Transactional.class));
|
||||
|
||||
AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(TestConsumerConfiguration.class);
|
||||
|
||||
TestConsumerConfiguration consumerConfiguration = consumerContext.getBean(TestConsumerConfiguration.class);
|
||||
|
||||
demoService = consumerConfiguration.getDemoService();
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assert.assertEquals("Hello,Mercy", value);
|
||||
|
||||
TestConsumerConfiguration.Child child = consumerContext.getBean(TestConsumerConfiguration.Child.class);
|
||||
|
||||
// From Child
|
||||
|
||||
demoService = child.getDemoServiceFromChild();
|
||||
|
||||
Assert.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assert.assertEquals("Hello,Mercy", value);
|
||||
|
||||
// From Parent
|
||||
|
||||
demoService = child.getDemoServiceFromParent();
|
||||
|
||||
Assert.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assert.assertEquals("Hello,Mercy", value);
|
||||
|
||||
// From Ancestor
|
||||
|
||||
demoService = child.getDemoServiceFromAncestor();
|
||||
|
||||
Assert.assertNotNull(demoService);
|
||||
|
||||
value = demoService.sayName("Mercy");
|
||||
|
||||
Assert.assertEquals("Hello,Mercy", value);
|
||||
|
||||
// Test my-registry2 bean presentation
|
||||
RegistryConfig registryConfig = consumerContext.getBean("my-registry2", RegistryConfig.class);
|
||||
|
||||
// Test multiple binding
|
||||
Assert.assertEquals("N/A", registryConfig.getAddress());
|
||||
|
||||
}
|
||||
|
||||
@EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
|
||||
@ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider")
|
||||
@PropertySource("classpath:/META-INF/dubbb-provider.properties")
|
||||
@EnableTransactionManagement
|
||||
public static class TestProviderConfiguration {
|
||||
|
||||
@Primary
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new PlatformTransactionManager() {
|
||||
|
||||
@Override
|
||||
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(TransactionStatus status) throws TransactionException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(TransactionStatus status) throws TransactionException {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation.consumer;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration("consumerConfiguration")
|
||||
@DubboComponentScan(
|
||||
basePackageClasses = ConsumerConfiguration.class
|
||||
)
|
||||
@PropertySource("META-INF/default.properties")
|
||||
public class ConsumerConfiguration {
|
||||
|
||||
/**
|
||||
* Current application configuration, to replace XML config:
|
||||
* <prev>
|
||||
* <dubbo:application name="dubbo-demo-application"/>
|
||||
* </prev>
|
||||
*
|
||||
* @return {@link ApplicationConfig} Bean
|
||||
*/
|
||||
@Bean("dubbo-demo-application")
|
||||
public ApplicationConfig applicationConfig() {
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig();
|
||||
applicationConfig.setName("dubbo-demo-application");
|
||||
return applicationConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current registry center configuration, to replace XML config:
|
||||
* <prev>
|
||||
* <dubbo:registry address="N/A"/>
|
||||
* </prev>
|
||||
*
|
||||
* @return {@link RegistryConfig} Bean
|
||||
*/
|
||||
@Bean
|
||||
public RegistryConfig registryConfig() {
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("N/A");
|
||||
return registryConfig;
|
||||
}
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345")
|
||||
private DemoService demoService;
|
||||
|
||||
public DemoService getDemoService() {
|
||||
return demoService;
|
||||
}
|
||||
|
||||
public void setDemoService(DemoService demoService) {
|
||||
this.demoService = demoService;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Child c() {
|
||||
return new Child();
|
||||
}
|
||||
|
||||
public static abstract class Ancestor {
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345")
|
||||
private DemoService demoServiceFromAncestor;
|
||||
|
||||
public DemoService getDemoServiceFromAncestor() {
|
||||
return demoServiceFromAncestor;
|
||||
}
|
||||
|
||||
public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) {
|
||||
this.demoServiceFromAncestor = demoServiceFromAncestor;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class Parent extends Ancestor {
|
||||
|
||||
private DemoService demoServiceFromParent;
|
||||
|
||||
public DemoService getDemoServiceFromParent() {
|
||||
return demoServiceFromParent;
|
||||
}
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345")
|
||||
public void setDemoServiceFromParent(DemoService demoServiceFromParent) {
|
||||
this.demoServiceFromParent = demoServiceFromParent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Child extends Parent {
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345")
|
||||
private DemoService demoServiceFromChild;
|
||||
|
||||
public DemoService getDemoServiceFromChild() {
|
||||
return demoServiceFromChild;
|
||||
}
|
||||
|
||||
public void setDemoServiceFromChild(DemoService demoServiceFromChild) {
|
||||
this.demoServiceFromChild = demoServiceFromChild;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation.consumer.test;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* Test Consumer Configuration
|
||||
*
|
||||
* @since 2.5.7
|
||||
*/
|
||||
@EnableDubbo(scanBasePackageClasses = TestConsumerConfiguration.class, multipleConfig = true)
|
||||
@PropertySource("META-INF/dubbb-consumer.properties")
|
||||
@EnableTransactionManagement
|
||||
public class TestConsumerConfiguration {
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application")
|
||||
private DemoService demoService;
|
||||
|
||||
public DemoService getDemoService() {
|
||||
return demoService;
|
||||
}
|
||||
|
||||
public void setDemoService(DemoService demoService) {
|
||||
this.demoService = demoService;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public TestConsumerConfiguration.Child c() {
|
||||
return new TestConsumerConfiguration.Child();
|
||||
}
|
||||
|
||||
public static abstract class Ancestor {
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application")
|
||||
private DemoService demoServiceFromAncestor;
|
||||
|
||||
public DemoService getDemoServiceFromAncestor() {
|
||||
return demoServiceFromAncestor;
|
||||
}
|
||||
|
||||
public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) {
|
||||
this.demoServiceFromAncestor = demoServiceFromAncestor;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class Parent extends TestConsumerConfiguration.Ancestor {
|
||||
|
||||
private DemoService demoServiceFromParent;
|
||||
|
||||
public DemoService getDemoServiceFromParent() {
|
||||
return demoServiceFromParent;
|
||||
}
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application")
|
||||
public void setDemoServiceFromParent(DemoService demoServiceFromParent) {
|
||||
this.demoServiceFromParent = demoServiceFromParent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Child extends TestConsumerConfiguration.Parent {
|
||||
|
||||
@Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application")
|
||||
private DemoService demoServiceFromChild;
|
||||
|
||||
public DemoService getDemoServiceFromChild() {
|
||||
return demoServiceFromChild;
|
||||
}
|
||||
|
||||
public void setDemoServiceFromChild(DemoService demoServiceFromChild) {
|
||||
this.demoServiceFromChild = demoServiceFromChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation.provider;
|
||||
|
||||
import org.apache.dubbo.config.spring.api.Box;
|
||||
import org.apache.dubbo.config.spring.api.DemoService;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* {@link DemoService} Service implementation
|
||||
*
|
||||
* @since 2.5.8
|
||||
*/
|
||||
@org.apache.dubbo.config.annotation.Service(
|
||||
version = "${demo.service.version}",
|
||||
application = "${demo.service.application}",
|
||||
protocol = "${demo.service.protocol}",
|
||||
registry = "${demo.service.registry}"
|
||||
)
|
||||
@Service
|
||||
@Transactional
|
||||
public class DemoServiceImpl implements DemoService {
|
||||
|
||||
@Override
|
||||
public String sayName(String name) {
|
||||
return "Hello," + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return new Box() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "MyBox";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation.provider;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.spring.api.HelloService;
|
||||
|
||||
/**
|
||||
* {@link HelloService} Implementation just annotating Dubbo's {@link Service}
|
||||
*
|
||||
* @since 2.5.9
|
||||
*/
|
||||
@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService")
|
||||
public class HelloServiceImpl implements HelloService {
|
||||
|
||||
@Override
|
||||
public String sayHello(String name) {
|
||||
return "Hello, " + name;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.annotation.provider;
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@DubboComponentScan(basePackages = "org.apache.dubbo")
|
||||
@ComponentScan(basePackages = "org.apache.dubbo")
|
||||
@PropertySource("META-INF/default.properties")
|
||||
@EnableTransactionManagement
|
||||
public class ProviderConfiguration {
|
||||
|
||||
/**
|
||||
* Current application configuration, to replace XML config:
|
||||
* <prev>
|
||||
* <dubbo:application name="dubbo-demo-application"/>
|
||||
* </prev>
|
||||
*
|
||||
* @return {@link ApplicationConfig} Bean
|
||||
*/
|
||||
@Bean("dubbo-demo-application")
|
||||
public ApplicationConfig applicationConfig() {
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig();
|
||||
applicationConfig.setName("dubbo-demo-application");
|
||||
return applicationConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current registry center configuration, to replace XML config:
|
||||
* <prev>
|
||||
* <dubbo:registry id="my-registry" address="N/A"/>
|
||||
* </prev>
|
||||
*
|
||||
* @return {@link RegistryConfig} Bean
|
||||
*/
|
||||
@Bean("my-registry")
|
||||
public RegistryConfig registryConfig() {
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("N/A");
|
||||
return registryConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current protocol configuration, to replace XML config:
|
||||
* <prev>
|
||||
* <dubbo:protocol name="dubbo" port="12345"/>
|
||||
* </prev>
|
||||
*
|
||||
* @return {@link ProtocolConfig} Bean
|
||||
*/
|
||||
@Bean("dubbo")
|
||||
public ProtocolConfig protocolConfig() {
|
||||
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setName("dubbo");
|
||||
protocolConfig.setPort(12345);
|
||||
return protocolConfig;
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean
|
||||
public PlatformTransactionManager platformTransactionManager() {
|
||||
return new PlatformTransactionManager() {
|
||||
|
||||
@Override
|
||||
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(TransactionStatus status) throws TransactionException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(TransactionStatus status) throws TransactionException {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.spring.context.context.properties;
|
||||
|
||||
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ConsumerConfig;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.spring.beans.factory.config.YamlPropertySourceFactory;
|
||||
import org.apache.dubbo.config.spring.context.properties.DefaultDubboConfigBinder;
|
||||
import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(locations = "classpath:/dubbo.properties")
|
||||
@PropertySource(name = "yaml-source", value = {"classpath:/META-INF/dubbo.yml"}, factory = YamlPropertySourceFactory.class)
|
||||
@Configuration
|
||||
@ContextConfiguration(classes = {DefaultDubboConfigBinder.class, DefaultDubboConfigBinderTest.class})
|
||||
public class DefaultDubboConfigBinderTest {
|
||||
|
||||
@Autowired
|
||||
private DubboConfigBinder dubboConfigBinder;
|
||||
|
||||
@Value("${dubbo.consumer.default}")
|
||||
private Boolean isDefault;
|
||||
|
||||
@Value("${dubbo.consumer.client}")
|
||||
private String client;
|
||||
|
||||
@Value("${dubbo.consumer.threadpool}")
|
||||
private String threadPool;
|
||||
|
||||
@Value("${dubbo.consumer.corethreads}")
|
||||
private Integer coreThreads;
|
||||
|
||||
@Value("${dubbo.consumer.threads}")
|
||||
private Integer threads;
|
||||
|
||||
@Value("${dubbo.consumer.queues}")
|
||||
private Integer queues;
|
||||
|
||||
@Test
|
||||
public void testBinder() {
|
||||
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig();
|
||||
dubboConfigBinder.bind("dubbo.application", applicationConfig);
|
||||
Assert.assertEquals("hello", applicationConfig.getName());
|
||||
Assert.assertEquals("world", applicationConfig.getOwner());
|
||||
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
dubboConfigBinder.bind("dubbo.registry", registryConfig);
|
||||
Assert.assertEquals("10.20.153.17", registryConfig.getAddress());
|
||||
|
||||
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||
dubboConfigBinder.bind("dubbo.protocol", protocolConfig);
|
||||
Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());
|
||||
|
||||
ConsumerConfig consumerConfig = new ConsumerConfig();
|
||||
dubboConfigBinder.bind("dubbo.consumer", consumerConfig);
|
||||
|
||||
Assert.assertEquals(isDefault, consumerConfig.isDefault());
|
||||
Assert.assertEquals(client, consumerConfig.getClient());
|
||||
Assert.assertEquals(threadPool, consumerConfig.getThreadpool());
|
||||
Assert.assertEquals(coreThreads, consumerConfig.getCorethreads());
|
||||
Assert.assertEquals(threads, consumerConfig.getThreads());
|
||||
Assert.assertEquals(queues, consumerConfig.getQueues());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-config</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.configcenter.support.nop;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* {@link NopDynamicConfiguration} Test
|
||||
*
|
||||
* @since 2.7.4
|
||||
*/
|
||||
public class NopDynamicConfigurationTest {
|
||||
|
||||
private NopDynamicConfiguration configuration = new NopDynamicConfiguration(null);
|
||||
|
||||
@Test
|
||||
public void testGetInternalProperty() {
|
||||
assertNull(configuration.getInternalProperty(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfig() {
|
||||
assertNull(configuration.getConfig(null, null, -1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetConfigs() {
|
||||
assertNull(configuration.getConfigs(null, null, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddListener() {
|
||||
configuration.addListener(null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveListener() {
|
||||
configuration.removeListener(null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublishConfig() {
|
||||
assertTrue(configuration.publishConfig(null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigKeys() {
|
||||
assertTrue(configuration.getConfigKeys(null).isEmpty());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-configcenter-apollo</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -97,11 +97,11 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
private String getAddressWithProtocolPrefix (URL url) {
|
||||
private String getAddressWithProtocolPrefix(URL url) {
|
||||
String address = url.getBackupAddress();
|
||||
if (StringUtils.isNotEmpty(address)) {
|
||||
address = Arrays.stream(COMMA_SPLIT_PATTERN.split(address))
|
||||
.map(addr -> {
|
||||
.map(addr -> {
|
||||
if (addr.startsWith(APOLLO_PROTOCOL_PREFIX)) {
|
||||
return addr;
|
||||
}
|
||||
|
|
@ -135,7 +135,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
if (StringUtils.isNotEmpty(group)) {
|
||||
if (group.equals(url.getParameter(APPLICATION_KEY))) {
|
||||
return ConfigService.getAppConfig().getProperty(key, null);
|
||||
|
|
@ -147,8 +147,8 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
if(StringUtils.isEmpty(group)) {
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
return dubboConfigFile.getContent();
|
||||
}
|
||||
if (group.equals(url.getParameter(APPLICATION_KEY))) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -93,16 +93,16 @@ public class ConsulDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
return (String) getInternalProperty(convertKey(group, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
group = DEFAULT_GROUP;
|
||||
}
|
||||
return (String) getInternalProperty(convertKey(group, key));
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent;
|
|||
import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
|
||||
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
|
||||
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.remoting.etcd.StateListener;
|
||||
import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
|
||||
|
||||
|
|
@ -95,18 +94,23 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
return (String) getInternalProperty(convertKey(group, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
group = DEFAULT_GROUP;
|
||||
}
|
||||
return (String) getInternalProperty(convertKey(group, key));
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getConfigs(String key, String group, long timeout) throws IllegalStateException {
|
||||
// if (StringUtils.isEmpty(group)) {
|
||||
// group = DEFAULT_GROUP;
|
||||
// }
|
||||
// return (String) getInternalProperty(convertKey(group, key));
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
return etcdClient.getKVValue(key);
|
||||
|
|
@ -118,7 +122,7 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
private void recover() {
|
||||
for (EtcdConfigWatcher watcher: watchListenerMap.values()) {
|
||||
for (EtcdConfigWatcher watcher : watchListenerMap.values()) {
|
||||
watcher.watch();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -185,9 +185,9 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
try {
|
||||
long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout;
|
||||
long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout;
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
group = DEFAULT_GROUP;
|
||||
}
|
||||
|
|
@ -199,8 +199,8 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getRule(key, group, timeout);
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ public class NacosDynamicConfigurationTest {
|
|||
Thread.sleep(200);
|
||||
put("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", "helloworld");
|
||||
Thread.sleep(200);
|
||||
Assertions.assertEquals("hello", config.getRule("org.apache.dubbo.nacos.testService.configurators", DynamicConfiguration.DEFAULT_GROUP));
|
||||
Assertions.assertEquals("aaa=bbb", config.getRule("dubbo.properties", "test"));
|
||||
Assertions.assertEquals("helloworld", config.getRule("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", DynamicConfiguration.DEFAULT_GROUP));
|
||||
Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.nacos.testService.configurators", DynamicConfiguration.DEFAULT_GROUP));
|
||||
Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test"));
|
||||
Assertions.assertEquals("helloworld", config.getConfig("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", DynamicConfiguration.DEFAULT_GROUP));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-configcenter-zookeeper</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -106,22 +106,23 @@ public class ZookeeperDynamicConfiguration implements DynamicConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
public String getConfig(String key, String group, long timeout) throws IllegalStateException {
|
||||
return (String) getInternalProperty(getPathKey(group, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule(String key, String group, long timeout) throws IllegalStateException {
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperties(String key, String group, long timeout) throws IllegalStateException {
|
||||
// use global group 'dubbo' if no group specified
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
group = DEFAULT_GROUP;
|
||||
}
|
||||
return (String) getInternalProperty(getPathKey(group, key));
|
||||
return getConfig(key, group, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String key, String group, String content) {
|
||||
String path = buildPath(key, group);
|
||||
String path = getPathKey(key, group);
|
||||
zkClient.create(path, content, true);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -133,41 +134,46 @@ public class ZookeeperDynamicConfiguration implements DynamicConfiguration {
|
|||
return isEmpty(nodes) ? emptySortedSet() : unmodifiableSortedSet(new TreeSet<>(nodes));
|
||||
}
|
||||
|
||||
private String buildPath(String group) {
|
||||
String actualGroup = StringUtils.isEmpty(group) ? DEFAULT_GROUP : group;
|
||||
return rootPath + PATH_SEPARATOR + actualGroup;
|
||||
}
|
||||
|
||||
private String getPathKey(String group, String key) {
|
||||
return rootPath + PATH_SEPARATOR + group + PATH_SEPARATOR + key;
|
||||
return buildPath(group) + PATH_SEPARATOR + key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the config node path by the specified <code>key</code> and <code>group</code>
|
||||
*
|
||||
* @param key the key to represent a configuration
|
||||
* @param group the group where the key belongs to
|
||||
* @return
|
||||
*/
|
||||
protected String buildPath(String key, String group) {
|
||||
String path = null;
|
||||
/**
|
||||
* when group is not null, we are getting startup configs from Config Center, for example:
|
||||
* group=dubbo, key=dubbo.properties
|
||||
*/
|
||||
if (StringUtils.isNotEmpty(group)) {
|
||||
path = group + "/" + key;
|
||||
}
|
||||
/**
|
||||
* when group is null, we are fetching governance rules, for example:
|
||||
* 1. key=org.apache.dubbo.DemoService.configurators
|
||||
* 2. key = org.apache.dubbo.DemoService.condition-router
|
||||
*/
|
||||
else {
|
||||
int i = key.lastIndexOf(".");
|
||||
path = key.substring(0, i) + "/" + key.substring(i + 1);
|
||||
}
|
||||
return buildPath(path);
|
||||
}
|
||||
|
||||
protected String buildPath(String relativePath) {
|
||||
String path = rootPath + "/" + relativePath;
|
||||
return path;
|
||||
}
|
||||
// /**
|
||||
// * Build the config node path by the specified <code>key</code> and <code>group</code>
|
||||
// *
|
||||
// * @param key the key to represent a configuration
|
||||
// * @param group the group where the key belongs to
|
||||
// * @return
|
||||
// */
|
||||
// protected String buildPath(String key, String group) {
|
||||
// String path = null;
|
||||
// /**
|
||||
// * when group is not null, we are getting startup configs from Config Center, for example:
|
||||
// * group=dubbo, key=dubbo.properties
|
||||
// */
|
||||
// if (StringUtils.isNotEmpty(group)) {
|
||||
// path = group + "/" + key;
|
||||
// }
|
||||
// /**
|
||||
// * when group is null, we are fetching governance rules, for example:
|
||||
// * 1. key=org.apache.dubbo.DemoService.configurators
|
||||
// * 2. key = org.apache.dubbo.DemoService.condition-router
|
||||
// */
|
||||
// else {
|
||||
// int i = key.lastIndexOf(".");
|
||||
// path = key.substring(0, i) + "/" + key.substring(i + 1);
|
||||
// }
|
||||
// return buildPath(path);
|
||||
// }
|
||||
//
|
||||
// protected String buildPath(String relativePath) {
|
||||
// String path = rootPath + "/" + relativePath;
|
||||
// return path;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class ZookeeperDynamicConfigurationTest {
|
|||
|
||||
@Test
|
||||
public void testGetConfig() throws Exception {
|
||||
Assertions.assertEquals("The content from dubbo.properties", configuration.getProperties("dubbo.properties", "dubbo"));
|
||||
Assertions.assertEquals("The content from dubbo.properties", configuration.getConfig("dubbo.properties", "dubbo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-configcenter</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-container</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-container-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-container</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-container-log4j</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-container</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-container-logback</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-container</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-container-spring</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-container</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo-annotation</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-annotation</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@
|
|||
#
|
||||
|
||||
dubbo.application.name=dubbo-demo-annotation-consumer
|
||||
dubbo.registry.address=multicast://224.5.6.7:1234
|
||||
dubbo.registry.address=zookeeper://127.0.0.1:2181
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo-annotation</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-annotation</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
public class Application {
|
||||
/**
|
||||
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
|
||||
* launch the application
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
|
||||
context.start();
|
||||
|
|
@ -44,7 +40,7 @@ public class Application {
|
|||
@Bean
|
||||
public RegistryConfig registryConfig() {
|
||||
RegistryConfig registryConfig = new RegistryConfig();
|
||||
registryConfig.setAddress("multicast://224.5.6.7:1234");
|
||||
registryConfig.setAddress("zookeeper://127.0.0.1:2181");
|
||||
return registryConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo-api</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,10 @@ import org.apache.dubbo.config.RegistryConfig;
|
|||
import org.apache.dubbo.demo.DemoService;
|
||||
|
||||
public class Application {
|
||||
/**
|
||||
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
|
||||
* launch the application
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
|
||||
reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
|
||||
reference.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
|
||||
reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
|
||||
reference.setInterface(DemoService.class);
|
||||
DemoService service = reference.get();
|
||||
String message = service.sayHello("dubbo");
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo-api</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,10 @@ import org.apache.dubbo.config.ServiceConfig;
|
|||
import org.apache.dubbo.demo.DemoService;
|
||||
|
||||
public class Application {
|
||||
/**
|
||||
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
|
||||
* launch the application
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
|
||||
service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
|
||||
service.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
|
||||
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
service.export();
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo-interface</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-xml</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo-xml-consumer</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ import org.apache.dubbo.demo.DemoService;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Application {
|
||||
/**
|
||||
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
|
||||
* launch the application
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
|
||||
context.start();
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@
|
|||
|
||||
<dubbo:application name="demo-consumer"/>
|
||||
|
||||
<dubbo:registry address="multicast://224.5.6.7:1234"/>
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- generate proxy for the remote service, then demoService can be used in the same way as the
|
||||
local regular interface -->
|
||||
<dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo-xml</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo-xml-provider</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -19,10 +19,6 @@ package org.apache.dubbo.demo.provider;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Application {
|
||||
/**
|
||||
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
|
||||
* launch the application
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml");
|
||||
context.start();
|
||||
|
|
|
|||
|
|
@ -21,18 +21,14 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
|
||||
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<!-- provider's application name, used for tracing dependency relationship -->
|
||||
<dubbo:application name="demo-provider"/>
|
||||
|
||||
<dubbo:registry address="multicast://224.5.6.7:1234" />
|
||||
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<!-- use dubbo protocol to export service on port 20880 -->
|
||||
<dubbo:protocol name="dubbo"/>
|
||||
|
||||
<!-- service implementation, as same as regular local bean -->
|
||||
<bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
|
||||
|
||||
<!-- declare the service interface to be exported -->
|
||||
<dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-distribution</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-filter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-filter-cache</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-filter</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-filter-validation</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-filter</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue