From 95893f60957ac44cc83d0d5859163484044f2984 Mon Sep 17 00:00:00 2001 From: jason Date: Sat, 21 Jul 2018 23:59:08 +0800 Subject: [PATCH] fix subscription when enable monitor --- .../alibaba/dubbo/config/AbstractInterfaceConfig.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractInterfaceConfig.java index 168bb10d2ea..87b50ebd971 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/AbstractInterfaceConfig.java @@ -36,6 +36,8 @@ import com.alibaba.dubbo.rpc.cluster.Cluster; import com.alibaba.dubbo.rpc.support.MockInvoker; +import static com.alibaba.dubbo.common.utils.NetUtils.isInvalidLocalHost; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -225,7 +227,16 @@ protected URL loadMonitor(URL registryURL) { if (ConfigUtils.getPid() > 0) { map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid())); } + //set ip + String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); + if (hostToRegistry == null || hostToRegistry.length() == 0) { + hostToRegistry = NetUtils.getLocalHost(); + } else if (isInvalidLocalHost(hostToRegistry)) { + throw new IllegalArgumentException("Specified invalid registry ip from property:" + Constants.DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry); + } + map.put(Constants.REGISTER_IP_KEY, hostToRegistry); appendParameters(map, monitor); + appendParameters(map, application); String address = monitor.getAddress(); String sysaddress = System.getProperty("dubbo.monitor.address"); if (sysaddress != null && sysaddress.length() > 0) {