Last active
May 30, 2020 18:29
-
-
Save gauravat16/8cd1b2ec05f8caba5450eaac05c300eb 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
@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