I have multiple SMS/email service providers. I want to apply load balancing, retry for the same provider, retry for another provider, fall and circuit breaker.
I try to use Spring-cloud-netfix-ribbon, but retry using LoadBalancerClient directly, because I have to reconstruct http request object for each provider differently. I am using apache http client to http requests. In my case Load balancer is working fine, but I am not able to configure retry for the apache http client.
I had added spring-retry on class-path. Some basic configuration:
spring.cloud.loadbalancer.retry.enabled=true
sms-service.ribbon.MaxAutoRetries=2
sms-service.ribbon.MaxAutoRetriesNextServer=1
sms-service.ribbon.ReadTimeout=1000
sms-service.ribbon.OkToRetryOnAllOperations=true
sms-service.ribbon.listOfServers=netcore,acl
loadBalancerClient.execute(serviceId, new LoadBalancerRequest<NotificationStatus>(){
@Override
public NotificationStatus apply(ServiceInstance instance) throws Exception {
logger.info("sms service provider: " + instance.getHost());
AbstractSmsService smsService = applicationContext.getBean(instance.getHost(), AbstractSmsService.class);
if (smsDto.getSmsType() == SmsType.OTP) {
return smsService.sendOtp(smsDto.getMobile(), smsDto.getCountryCode(), smsDto.getText());
} else {
return smsService.sendText(smsDto.getMobile(), smsDto.getCountryCode(), smsDto.getText());
}
}
});
I want if any error is occurred, ribbon must retry to the same provider and for the other provider as configured.