0

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.

Deepak Agrawal
  • 1,301
  • 5
  • 19
  • 43
  • try adding this in a configuration class, public void retryTemplate(RetryTemplate template){ template.setRetryPolicy(new SimpleRetryPolicy(3)); } mark the method as @Autowired – Keaz Jul 17 '18 at 13:40
  • @Keaz thanks for reply. I am not using Apache Http Client not Rest template. – Deepak Agrawal Jul 17 '18 at 15:09

0 Answers0