Skip to content

Instantly share code, notes, and snippets.

@xie-qianyue
Created June 15, 2018 05:58
Show Gist options
  • Save xie-qianyue/867a0481dff76ada15d9e9d63082e068 to your computer and use it in GitHub Desktop.
Save xie-qianyue/867a0481dff76ada15d9e9d63082e068 to your computer and use it in GitHub Desktop.
custom routing rule for Ribbon
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