Reputation: 97
I want to go to the fallback when any of the routes return 404 HTTP Code. The reason is that if a resource is not found, the route should try to fetch that from the fallback Uri.
Following is my .yml defined. What I am trying to achieve is if the elastic search didn't find my record and returns 404. Search in fallback i.e. database. But I am getting 404 from the gateway in this case. Is there any way to achieve this.?
spring:
application:
name: gateway
sleuth:
sampler:
probability: 1.0
cloud:
gateway:
discovery:
locator:
enabled: true
- id: search_route
uri: lb://ELASTIC_SEARCH_SERVICE
predicates:
- Path=/unison/search/**
filters:
- name: Hystrix
args:
name: fallbackCommand
fallbackUri: forward:/search/rdbms
Upvotes: 2
Views: 1817
Reputation: 1645
You must make the gateway aware of the eureka server with this
eureka.client.service-url.defaultZone=http://user:pass@localhost:8761/eureka
And then prevent the gateway from registerin itself to eureka
eureka.client.register-with-eureka=false
The second option is important as it causes 404 errors with loadbalancing using lb:servicename structure.
Upvotes: 1