|
|
@@ -1,6 +1,7 @@
|
|
|
package com.mrxu.framework.boot.irule;
|
|
|
|
|
|
import cn.hutool.core.net.NetUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.mrxu.framework.boot.config.MetaFilterAutoConfiguration;
|
|
|
import com.mrxu.framework.common.MrxuConst;
|
|
|
import com.netflix.loadbalancer.ILoadBalancer;
|
|
|
@@ -23,7 +24,7 @@ public class MetadataAwareRule extends ZoneAvoidanceRule {
|
|
|
public Server choose(Object key) {
|
|
|
log.debug("开启微服务本地调试");
|
|
|
ILoadBalancer lb = getLoadBalancer();
|
|
|
- String localMac = NetUtil.getLocalMacAddress();
|
|
|
+ String localMac = getMetaMac();
|
|
|
List<Server> upList = lb.getReachableServers();
|
|
|
// 优先查找本机可用服务
|
|
|
for(Server upServer : upList) {
|
|
|
@@ -60,4 +61,13 @@ public class MetadataAwareRule extends ZoneAvoidanceRule {
|
|
|
//没有找到合适的服务使用默认规则
|
|
|
return super.choose(key);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ // 获取本地mac 机器唯一标记
|
|
|
+ public static String getMetaMac() {
|
|
|
+ String mac = NetUtil.getLocalMacAddress();
|
|
|
+ if(StrUtil.isEmpty(mac)) {
|
|
|
+ mac = NetUtil.getLocalhostStr();
|
|
|
+ }
|
|
|
+ return mac;
|
|
|
+ }
|
|
|
+}
|