Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add DNS Mode as default peer resolver #14845

Open
wants to merge 6 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dubbo-common/src/main/java/org/apache/dubbo/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,14 @@ public interface Constants {
String DEFAULT_NATIVE_PROXY = "jdk";

String DEFAULT_APP_NAME = "DEFAULT_DUBBO_APP";

String DNS_NAME = "dnsName";

String TARGET_PORT = "targetPort";

String TARGET_PROTOCOL = "targetProtocol";

String DNS_REGISTRY = "dns";

String DNS_DEFAULT_NAMESERVER = "DEFAULT_DNS_HOST";
}
7 changes: 7 additions & 0 deletions dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-dns</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NetUtils;
Expand All @@ -40,7 +39,6 @@
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster;
import org.apache.dubbo.rpc.model.AsyncMethodInfo;
import org.apache.dubbo.rpc.model.ConsumerModel;
Expand All @@ -65,6 +63,7 @@
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_DOMAIN;
Expand All @@ -76,14 +75,14 @@
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_MESH_PORT;
import static org.apache.dubbo.common.constants.CommonConstants.DubboProperty.DUBBO_IP_TO_REGISTRY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.MESH_ENABLE;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.POD_NAMESPACE;
import static org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SVC;
import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE;
Expand All @@ -101,7 +100,7 @@
import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.cluster.Constants.PEER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;

/**
Expand Down Expand Up @@ -492,13 +491,7 @@ private T createProxy(Map<String, String> referenceParameters) {

meshModeHandleUrl(referenceParameters);

if (StringUtils.isNotEmpty(url)) {
// user specified URL, could be peer-to-peer address, or register center's address.
parseUrl(referenceParameters);
} else {
// if protocols not in jvm checkRegistry
aggregateUrlFromRegistry(referenceParameters);
}
aggregateUrlFromRegistry(referenceParameters);
createInvoker();

if (logger.isInfoEnabled()) {
Expand Down Expand Up @@ -599,39 +592,41 @@ private boolean checkMeshConfig(Map<String, String> referenceParameters) {
return true;
}

/**
* Parse the directly configured url.
*/
private void parseUrl(Map<String, String> referenceParameters) {
String[] us = SEMICOLON_SPLIT_PATTERN.split(url);
if (ArrayUtils.isNotEmpty(us)) {
for (String u : us) {
URL url = URL.valueOf(u);
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(interfaceName);
}
url = url.setScopeModel(getScopeModel());
url = url.setServiceModel(consumerModel);
if (UrlUtils.isRegistry(url)) {
urls.add(url.putAttribute(REFER_KEY, referenceParameters));
} else {
URL peerUrl = getScopeModel()
.getApplicationModel()
.getBeanFactory()
.getBean(ClusterUtils.class)
.mergeUrl(url, referenceParameters);
peerUrl = peerUrl.putAttribute(PEER_KEY, true);
urls.add(peerUrl);
}
}
}
}

/**
* Get URLs from the registry and aggregate them.
*/
private void aggregateUrlFromRegistry(Map<String, String> referenceParameters) {
checkRegistry();
if (StringUtils.isNoneEmpty(url)) {
// user specified URL, could be peer-to-peer address, or register center's address.
URL u = URL.valueOf(url);
if (StringUtils.isEmpty(u.getPath())) {
u = u.setPath(interfaceName);
}
referenceParameters.put(Constants.TARGET_PROTOCOL, u.getProtocol());
referenceParameters.put(Constants.DNS_NAME, u.getHost());
referenceParameters.put(Constants.TARGET_PORT, String.valueOf(u.getPort()));
u.getParameters().forEach(referenceParameters::putIfAbsent);
// Use sticky first to reduce connections
referenceParameters.putIfAbsent(CLUSTER_STICKY_KEY, Boolean.TRUE.toString());
// TODO Triple should support lazy connect
referenceParameters.putIfAbsent(LAZY_CONNECT_KEY, Boolean.TRUE.toString());

if (!getRegistries().isEmpty()) {
// If the URL has been set, only support DNS registry
setRegistries(getRegistries().stream()
.filter(registryConfig -> Constants.DNS_REGISTRY.equals(registryConfig.getProtocol()))
.collect(Collectors.toList()));
}
if (getRegistries().isEmpty()) {
// If none of the registries are configured, use the default DNS registry
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setProtocol(Constants.DNS_REGISTRY);
registryConfig.setAddress(Constants.DNS_DEFAULT_NAMESERVER);
registryConfig.refresh();
setRegistry(registryConfig);
}
}
List<URL> us = ConfigValidationUtils.loadRegistries(this, false);
if (CollectionUtils.isNotEmpty(us)) {
for (URL u : us) {
Expand Down
5 changes: 5 additions & 0 deletions dubbo-demo/dubbo-demo-triple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<artifactId>dubbo-registry-nacos</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-dns</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
*/
package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.GreeterService;
import org.apache.dubbo.demo.hello.HelloReply;
Expand All @@ -36,9 +33,7 @@ public class ApiConsumer {
public static void main(String[] args) throws InterruptedException {
ReferenceConfig<GreeterService> referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(GreeterService.class);
referenceConfig.setCheck(false);
referenceConfig.setProtocol(CommonConstants.TRIPLE);
referenceConfig.setLazy(true);
referenceConfig.setUrl("tri://localhost:50051");
referenceConfig.setTimeout(100000);
if (args.length > 0 && Constants.HTTP3_KEY.equals(args[0])) {
referenceConfig.setParameters(Collections.singletonMap(Constants.HTTP3_KEY, "true"));
Expand All @@ -47,8 +42,6 @@ public static void main(String[] args) throws InterruptedException {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap
.application(new ApplicationConfig("dubbo-demo-triple-api-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.reference(referenceConfig)
.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.GreeterService;
Expand All @@ -41,8 +40,7 @@ public static void main(String[] args) {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap
.application(new ApplicationConfig("dubbo-demo-triple-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
.service(serviceConfig)
.start()
.await();
Expand Down
8 changes: 8 additions & 0 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-dns</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- remoting -->
<dependency>
Expand Down Expand Up @@ -496,6 +503,7 @@
<include>org.apache.dubbo:dubbo-registry-multiple</include>
<include>org.apache.dubbo:dubbo-registry-nacos</include>
<include>org.apache.dubbo:dubbo-registry-zookeeper</include>
<include>org.apache.dubbo:dubbo-registry-dns</include>
<include>org.apache.dubbo:dubbo-remoting-api</include>
<include>org.apache.dubbo:dubbo-remoting-http12</include>
<include>org.apache.dubbo:dubbo-remoting-http3</include>
Expand Down
46 changes: 46 additions & 0 deletions dubbo-registry/dubbo-registry-dns/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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-registry</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dubbo-registry-dns</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>The DNS registry module of dubbo project</description>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
</dependencies>

</project>
Loading
Loading