Skip to content

Commit f65816d

Browse files
hengyunabcbeiwei30
authored andcommitted
qos support host config. apache#4720 (apache#4726)
1 parent a8785e9 commit f65816d

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/constants/QosConstants.java

+4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ public interface QosConstants {
2424

2525
String QOS_ENABLE = "qos.enable";
2626

27+
String QOS_HOST = "qos.host";
28+
2729
String QOS_PORT = "qos.port";
2830

2931
String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip";
3032

3133
String QOS_ENABLE_COMPATIBLE = "qos-enable";
3234

35+
String QOS_HOST_COMPATIBLE = "qos-host";
36+
3337
String QOS_PORT_COMPATIBLE = "qos-port";
3438

3539
String ACCEPT_FOREIGN_IP_COMPATIBLE = "qos-accept-foreign-ip";

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java

+25
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_COMPATIBLE;
4141
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
4242
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE_COMPATIBLE;
43+
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
44+
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST_COMPATIBLE;
4345
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
4446
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT_COMPATIBLE;
4547
import static org.apache.dubbo.config.Constants.ARCHITECTURE;
@@ -127,6 +129,11 @@ public class ApplicationConfig extends AbstractConfig {
127129
*/
128130
private Boolean qosEnable;
129131

132+
/**
133+
* The qos host to listen
134+
*/
135+
private String qosHost;
136+
130137
/**
131138
* The qos port to listen
132139
*/
@@ -309,6 +316,15 @@ public void setQosEnable(Boolean qosEnable) {
309316
this.qosEnable = qosEnable;
310317
}
311318

319+
@Parameter(key = QOS_HOST)
320+
public String getQosHost() {
321+
return qosHost;
322+
}
323+
324+
public void setQosHost(String qosHost) {
325+
this.qosHost = qosHost;
326+
}
327+
312328
@Parameter(key = QOS_PORT)
313329
public Integer getQosPort() {
314330
return qosPort;
@@ -340,6 +356,15 @@ public void setQosEnableCompatible(Boolean qosEnable) {
340356
setQosEnable(qosEnable);
341357
}
342358

359+
@Parameter(key = QOS_HOST_COMPATIBLE, excluded = true)
360+
public String getQosHostCompatible() {
361+
return getQosHost();
362+
}
363+
364+
public void setQosHostCompatible(String qosHost) {
365+
this.setQosHost(qosHost);
366+
}
367+
343368
@Parameter(key = QOS_PORT_COMPATIBLE, excluded = true)
344369
public Integer getQosPortCompatible() {
345370
return getQosPort();

dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
3232
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
33+
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
3334
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
3435
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
3536

@@ -92,9 +93,11 @@ private void startQosServer(URL url) {
9293
return;
9394
}
9495

96+
String host = url.getParameter(QOS_HOST);
9597
int port = url.getParameter(QOS_PORT, QosConstants.DEFAULT_PORT);
9698
boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP, "false"));
9799
Server server = Server.getInstance();
100+
server.setHost(host);
98101
server.setPort(port);
99102
server.setAcceptForeignIp(acceptForeignIp);
100103
server.start();

dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.dubbo.common.logger.Logger;
2020
import org.apache.dubbo.common.logger.LoggerFactory;
21+
import org.apache.dubbo.common.utils.StringUtils;
2122
import org.apache.dubbo.qos.server.handler.QosProcessHandler;
2223

2324
import io.netty.bootstrap.ServerBootstrap;
@@ -48,6 +49,8 @@ public static final Server getInstance() {
4849
return INSTANCE;
4950
}
5051

52+
private String host;
53+
5154
private int port;
5255

5356
private boolean acceptForeignIp = true;
@@ -97,7 +100,12 @@ protected void initChannel(Channel ch) throws Exception {
97100
}
98101
});
99102
try {
100-
serverBootstrap.bind(port).sync();
103+
if (StringUtils.isBlank(host)) {
104+
serverBootstrap.bind(port).sync();
105+
} else {
106+
serverBootstrap.bind(host, port).sync();
107+
}
108+
101109
logger.info("qos-server bind localhost:" + port);
102110
} catch (Throwable throwable) {
103111
logger.error("qos-server can not bind localhost:" + port, throwable);
@@ -118,6 +126,14 @@ public void stop() {
118126
}
119127
}
120128

129+
public String getHost() {
130+
return host;
131+
}
132+
133+
public void setHost(String host) {
134+
this.host = host;
135+
}
136+
121137
public void setPort(int port) {
122138
this.port = port;
123139
}

dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
3131
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
32+
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
3233
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
3334
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
3435
import static org.hamcrest.MatcherAssert.assertThat;
@@ -47,6 +48,7 @@ public class QosProtocolWrapperTest {
4748
@BeforeEach
4849
public void setUp() throws Exception {
4950
when(url.getParameter(QOS_ENABLE, true)).thenReturn(true);
51+
when(url.getParameter(QOS_HOST)).thenReturn("localhost");
5052
when(url.getParameter(QOS_PORT, 22222)).thenReturn(12345);
5153
when(url.getParameter(ACCEPT_FOREIGN_IP, true)).thenReturn(false);
5254
when(invoker.getUrl()).thenReturn(url);
@@ -64,6 +66,7 @@ public void tearDown() throws Exception {
6466
public void testExport() throws Exception {
6567
wrapper.export(invoker);
6668
assertThat(server.isStarted(), is(true));
69+
assertThat(server.getHost(), is("localhost"));
6770
assertThat(server.getPort(), is(12345));
6871
assertThat(server.isAcceptForeignIp(), is(false));
6972
verify(protocol).export(invoker);
@@ -73,6 +76,7 @@ public void testExport() throws Exception {
7376
public void testRefer() throws Exception {
7477
wrapper.refer(BaseCommand.class, url);
7578
assertThat(server.isStarted(), is(true));
79+
assertThat(server.getHost(), is("localhost"));
7680
assertThat(server.getPort(), is(12345));
7781
assertThat(server.isAcceptForeignIp(), is(false));
7882
verify(protocol).refer(BaseCommand.class, url);

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import static org.apache.dubbo.common.constants.FilterConstants.VALIDATION_KEY;
7070
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
7171
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
72+
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
7273
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
7374
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
7475
import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY;
@@ -318,7 +319,7 @@ private URL getRegisteredProviderUrl(final URL providerUrl, final URL registryUr
318319
//The address you see at the registry
319320
if (!registryUrl.getParameter(SIMPLIFIED_KEY, false)) {
320321
return providerUrl.removeParameters(getFilteredKeys(providerUrl)).removeParameters(
321-
MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
322+
MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, QOS_HOST, QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
322323
INTERFACES);
323324
} else {
324325
String extraKeys = registryUrl.getParameter(EXTRA_KEYS_KEY, "");

0 commit comments

Comments
 (0)