Created
May 30, 2020 18:01
-
-
Save gauravat16/dc538749263dd74fe2f4ac7937eab267 to your computer and use it in GitHub Desktop.
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
@Configuration | |
@RibbonClient(name = "payment-gateway", configuration = PaymentGatewayConfiguration.class) | |
public class PaymentGatewayConfiguration { | |
@Bean | |
public IPing ribbonPing(IClientConfig config) { | |
return new PingUrl(); | |
} | |
@Bean | |
public IRule ribbonRule(IClientConfig config) { | |
return new RandomRule(); | |
} | |
@Bean | |
public ServerList<Server> getServerList() { | |
return new ServerList<Server>() { | |
@Override | |
public List<Server> getInitialListOfServers() { | |
return new ArrayList<>(); | |
} | |
@Override | |
public List<Server> getUpdatedListOfServers() { | |
int totalServers = 10; | |
List<Server> serverList = new ArrayList<>(); | |
for (Server server : gatewayConfig.getGatewayURLMap().values()) { | |
if (server instanceof GatewayServer) { | |
int count = (int) (((GatewayServer) server).getRatio() * totalServers); | |
while (count-- > 0 && serverList.size() < totalServers) { | |
serverList.add(server); | |
} | |
} | |
} | |
return serverList; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment