Created
June 15, 2018 05:58
-
-
Save xie-qianyue/867a0481dff76ada15d9e9d63082e068 to your computer and use it in GitHub Desktop.
custom routing rule for Ribbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DevLBRule extends AbstractLoadBalancerRule { | |
@Value("${some.ip.prefix}") | |
private String ipPrefix = "10.20."; | |
@Override | |
public void initWithNiwsConfig(IClientConfig iClientConfig) { | |
} | |
@Override | |
public Server choose(Object key) { | |
List<Server> upList = getLoadBalancer().getReachableServers(); | |
if (upList != null) { | |
for (Server server : upList) { | |
if (server.getHost().startsWith(ipPrefix)) { | |
return server; | |
} | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment