Skip to content

Instantly share code, notes, and snippets.

@gauravat16
Last active May 30, 2020 18:29
Show Gist options
  • Save gauravat16/8cd1b2ec05f8caba5450eaac05c300eb to your computer and use it in GitHub Desktop.
Save gauravat16/8cd1b2ec05f8caba5450eaac05c300eb to your computer and use it in GitHub Desktop.
@Service
public class GatewayUtilServiceImpl implements GatewayUtilService {
@Autowired
private LoadBalancerClient loadBalancer;
@Override
public PaymentGateway getPaymentGateway() {
ServiceInstance instance = loadBalancer.choose("payment-gateway");
if (instance instanceof RibbonLoadBalancerClient.RibbonServer) {
Server server = ((RibbonLoadBalancerClient.RibbonServer) instance).getServer();
if (server instanceof GatewayServer) {
return ((GatewayServer) server).getGateway();
}
}
throw new IllegalArgumentException("No payment gateway found!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment