diff --git a/api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java b/api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java index 959e460e2..d7c7d3c0a 100644 --- a/api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java +++ b/api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java @@ -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. */ diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/core/PushReceiver.java b/client/src/main/java/com/alibaba/nacos/client/naming/core/PushReceiver.java index 3a0776d46..2b3b9973d 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/core/PushReceiver.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/core/PushReceiver.java @@ -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) {