[ISSUE #5180] Support domain resolution to obtain the nameserver address (#5189)

* [ISSUE #5180] Support domain resolution to obtain the nameserver address

* [ISSUE #5180] Support domain resolution to obtain the nameserver address

Co-authored-by: 斜阳 <terrance.lzm@alibaba-inc.com>
This commit is contained in:
lizhimins
2022-09-26 19:15:29 +08:00
committed by GitHub
co-authored by 斜阳
parent 5723b97964
commit a3e596550d
7 changed files with 89 additions and 5 deletions
@@ -112,6 +112,7 @@ public class BrokerContainer implements IBrokerContainer {
return nettyServerConfig;
}
@Override
public NettyClientConfig getNettyClientConfig() {
return nettyClientConfig;
}
@@ -130,6 +131,14 @@ public class BrokerContainer implements IBrokerContainer {
return this.configuration;
}
private void updateNamesrvAddr() {
if (this.brokerContainerConfig.isFetchNameSrvAddrByDnsLookup()) {
this.brokerOuterAPI.updateNameServerAddressListByDnsLookup(this.brokerContainerConfig.getNamesrvAddr());
} else {
this.brokerOuterAPI.updateNameServerAddressList(this.brokerContainerConfig.getNamesrvAddr());
}
}
public boolean initialize() {
this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, this.containerClientHouseKeepingService);
this.fastRemotingServer = this.remotingServer.newRemotingServer(this.nettyServerConfig.getListenPort() - 2);
@@ -145,14 +154,14 @@ public class BrokerContainer implements IBrokerContainer {
this.registerProcessor();
if (this.brokerContainerConfig.getNamesrvAddr() != null) {
this.brokerOuterAPI.updateNameServerAddressList(this.brokerContainerConfig.getNamesrvAddr());
this.updateNamesrvAddr();
LOG.info("Set user specified name server address: {}", this.brokerContainerConfig.getNamesrvAddr());
// also auto update namesrv if specify
this.scheduledExecutorService.scheduleAtFixedRate(new AbstractBrokerRunnable(BrokerIdentity.BROKER_CONTAINER_IDENTITY) {
@Override
public void run2() {
try {
BrokerContainer.this.brokerOuterAPI.updateNameServerAddressList(BrokerContainer.this.brokerContainerConfig.getNamesrvAddr());
BrokerContainer.this.updateNamesrvAddr();
} catch (Throwable e) {
LOG.error("ScheduledTask fetchNameServerAddr exception", e);
}
@@ -28,6 +28,9 @@ public class BrokerContainerConfig {
@ImportantField
private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, System.getenv(MixAll.NAMESRV_ADDR_ENV));
@ImportantField
private boolean fetchNameSrvAddrByDnsLookup = false;
@ImportantField
private boolean fetchNamesrvAddrByAddressServer = false;
@@ -52,6 +55,14 @@ public class BrokerContainerConfig {
this.namesrvAddr = namesrvAddr;
}
public boolean isFetchNameSrvAddrByDnsLookup() {
return fetchNameSrvAddrByDnsLookup;
}
public void setFetchNameSrvAddrByDnsLookup(boolean fetchNameSrvAddrByDnsLookup) {
this.fetchNameSrvAddrByDnsLookup = fetchNameSrvAddrByDnsLookup;
}
public boolean isFetchNamesrvAddrByAddressServer() {
return fetchNamesrvAddrByAddressServer;
}