update 修改多团队开发插件,支持多网卡
parent
0b810c0b8d
commit
5e03a2c1f1
|
|
@ -31,5 +31,10 @@
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package com.ruoyi.common.loadbalance.constant;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 常量类
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class LoadBalancerConstant {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取服务host
|
|
||||||
* 默认自动获取
|
|
||||||
*/
|
|
||||||
public static String getHost() {
|
|
||||||
String host = "127.0.0.1";
|
|
||||||
try {
|
|
||||||
// 如需自定义ip可修改此处
|
|
||||||
String address = InetAddress.getLocalHost().getHostAddress();
|
|
||||||
if (address != null) {
|
|
||||||
host = address;
|
|
||||||
}
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
log.debug("[LoadBalancer] - 本机IP地址: {}", host);
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.ruoyi.common.loadbalance.core;
|
package com.ruoyi.common.loadbalance.core;
|
||||||
|
|
||||||
import com.ruoyi.common.loadbalance.constant.LoadBalancerConstant;
|
import cn.hutool.core.net.NetUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.common.URL;
|
import org.apache.dubbo.common.URL;
|
||||||
import org.apache.dubbo.rpc.Invocation;
|
import org.apache.dubbo.rpc.Invocation;
|
||||||
|
|
@ -21,7 +21,7 @@ public class CustomDubboLoadBalancer extends AbstractLoadBalance {
|
||||||
@Override
|
@Override
|
||||||
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
|
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
|
||||||
for (Invoker<T> invoker : invokers) {
|
for (Invoker<T> invoker : invokers) {
|
||||||
if (invoker.getUrl().getHost().equals(LoadBalancerConstant.getHost())) {
|
if (NetUtil.localIpv4s().contains(invoker.getUrl().getHost())) {
|
||||||
return invoker;
|
return invoker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.ruoyi.common.loadbalance.core;
|
package com.ruoyi.common.loadbalance.core;
|
||||||
|
|
||||||
import com.ruoyi.common.loadbalance.constant.LoadBalancerConstant;
|
import cn.hutool.core.net.NetUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
|
@ -54,7 +54,7 @@ public class CustomSpringCloudLoadBalancer implements ReactorServiceInstanceLoad
|
||||||
return new EmptyResponse();
|
return new EmptyResponse();
|
||||||
}
|
}
|
||||||
for (ServiceInstance instance : instances) {
|
for (ServiceInstance instance : instances) {
|
||||||
if (instance.getHost().equals(LoadBalancerConstant.getHost())) {
|
if (NetUtil.localIpv4s().contains(instance.getHost())) {
|
||||||
return new DefaultResponse(instance);
|
return new DefaultResponse(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue