Support specified naming UDP push port for client (#5439)
* Nacos client within docker container could not receive service changes via udp * change code style
This commit is contained in:
parent
e0fe828542
commit
103e671d90
@ -64,11 +64,13 @@ public class PropertyKeyConst {
|
||||
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
|
||||
public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";
|
||||
|
||||
public static final String NAMING_PUSH_EMPTY_PROTECTION = "namingPushEmptyProtection";
|
||||
|
||||
|
||||
public static final String PUSH_RECEIVER_UDP_PORT = "push.receiver.udp.port";
|
||||
|
||||
/**
|
||||
* Get the key value of some variable value from the system property.
|
||||
*/
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package com.alibaba.nacos.client.naming.core;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.common.lifecycle.Closeable;
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
@ -25,6 +26,7 @@ import com.alibaba.nacos.common.utils.ThreadUtils;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
@ -51,10 +53,19 @@ public class PushReceiver implements Runnable, Closeable {
|
||||
|
||||
private volatile boolean closed = false;
|
||||
|
||||
public static String getPushReceiverUdpPort() {
|
||||
return System.getenv(PropertyKeyConst.PUSH_RECEIVER_UDP_PORT);
|
||||
}
|
||||
|
||||
public PushReceiver(HostReactor hostReactor) {
|
||||
try {
|
||||
this.hostReactor = hostReactor;
|
||||
this.udpSocket = new DatagramSocket();
|
||||
String udpPort = getPushReceiverUdpPort();
|
||||
if (StringUtils.isEmpty(udpPort)) {
|
||||
this.udpSocket = new DatagramSocket();
|
||||
} else {
|
||||
this.udpSocket = new DatagramSocket(new InetSocketAddress(Integer.parseInt(udpPort)));
|
||||
}
|
||||
this.executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
|
Loading…
Reference in New Issue
Block a user