2

I have configured zuul with 2 instances using ribbon (without eureka) as below:

zuul.retryable=true
zuul.routes.simple-ms-app.serviceId: client
client.ribbon.listOfServers=http://localhost:7788,http://localhost:8877

When both the instances 7788 & 8877 are up and running, everything goes fine.

When the first instance in the listOfServers is down, then the request ends up in the below error:

com.netflix.zuul.exception.ZuulException: Forwarding error

I am using the below version configuration:

spring-boot : 2.0.7.RELEASE spring-cloud: Finchley.SR2

If anyone had faced similar issue and managed to figure out a solution, please share it here.

Thank you.

snmaddula
  • 1,111
  • 1
  • 7
  • 21

1 Answers1

0

By default, Zuul throws exception (instead of throwing 503/404) when upstream service is not available. This behavior has been discussed in detail in Zuul swallows 503 exceptions from upstream microservices GitHub thread.

To handle this case and configure Zuul to retry on (current and next ) available instances, you need to do two things:

  • Extend ErrorFilter and handle the exception with custom behavior
  • Configure retry for Zuul

Extend ErrorFilter and provide custom logic to return 404 or 503 status code. Some of the approaches to deal with this exception is explain in this SO thread: Customizing Zuul Exception.

Retry in Zuul can be configured using following application properties:

zuul:
  retryable: true

ribbon:
  MaxAutoRetries: 1
  MaxAutoRetriesNextServer: 3
  OkToRetryOnAllOperations: true

yourApplication:
    ribbon:
        listOfServers: instance-1-url, instance-2-url

Please note that Spring retry is a dependency for retry in Zuul.

narendra-choudhary
  • 4,582
  • 4
  • 38
  • 58