spring-cloud-gateway: Spring Cloud Gateway unable to resolve Eureka DNS
Describe the bug I have a microservice architecture application that uses Spring Cloud Gateway as the API Gateway and Eureka Server as Service Discovery. I have tried accessing the path directly at that port and it works. However, I can’t seems to route the request to the respective microservice based on the path.
2020-12-28 13:52:07.452 TRACE 24764 --- [ctor-http-nio-6] o.s.c.g.h.p.PathRoutePredicateFactory : Pattern "/product/v3/api-docs" matches against value "/product/v3/api-docs"
2020-12-28 13:52:07.452 DEBUG 24764 --- [ctor-http-nio-6] o.s.c.g.h.RoutePredicateHandlerMapping : Route matched: product-service
2020-12-28 13:52:07.453 DEBUG 24764 --- [ctor-http-nio-6] o.s.c.g.h.RoutePredicateHandlerMapping : Mapping [Exchange: GET http://localhost:8080/product/v3/api-docs] to Route{id='product-service', uri=http://product-service:80, order=0, predicate=Paths: [/api/products/**, /api/products**, /product/v3/api-docs], match trailing slash: true, gatewayFilters=[], metadata={}}
2020-12-28 13:52:07.453 DEBUG 24764 --- [ctor-http-nio-6] o.s.c.g.h.RoutePredicateHandlerMapping : [5dbe450f-8] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@5d9e5006
2020-12-28 13:52:07.453 DEBUG 24764 --- [ctor-http-nio-6] o.s.c.g.handler.FilteringWebHandler : Sorted gatewayFilterFactories: [[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@6326c5ec}, order = -2147483648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@283d3628}, order = -2147482648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@7a2a7492}, order = -1], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@59baf2c7}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@138a85d3}, order = 10000], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@21e484b}, order = 10150], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@ce655b9}, order = 2147483646], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@191f4d65}, order = 2147483647], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@709d86a2}, order = 2147483647]]
2020-12-28 13:52:07.453 TRACE 24764 --- [ctor-http-nio-6] o.s.c.g.filter.RouteToRequestUrlFilter : RouteToRequestUrlFilter start
2020-12-28 13:52:07.478 ERROR 24764 --- [ctor-http-nio-4] a.w.r.e.AbstractErrorWebExceptionHandler : [5dbe450f-8] 500 Server Error for HTTP GET "/product/v3/api-docs"
java.net.UnknownHostException: failed to resolve 'product-service' after 2 queries
at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ? org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ? HTTP GET "/product/v3/api-docs" [ExceptionHandlingWebHandler]
Spring Boot Version: 2.4.1, Spring Cloud version: 2020.0.0 Tested on Spring Boot Version 2.3.7, Spring Cloud version hoxton sr9 and it works.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 25 (3 by maintainers)
eureka.instance.hostname=localhostadd this config to your microservicehello guys. Was the same problem. In all services and eureka server i add: cloud 2020.0.1 boot 2.4.3 java 11
eureka: instance: prefer-ip-address: true
and double to eureka-server:
eureka: instance: hostname: localhost
summary i have 3 instances:
eureka server yml: server: port: 8761
eureka: instance: prefer-ip-address: true hostname: localhost client: register-with-eureka: false fetch-registry: false
spring: application: name: registry
eureka client yml: server: port: 8181
spring: application: name: customers
eureka: instance: prefer-ip-address: true
and gateway yml: spring: cloud: loadbalancer: ribbon: enabled: false gateway: metrics: enabled: true discovery: locator: enabled: true lower-case-service-id: true application: name: gateway eureka: instance: prefer-ip-address: true
and routing for gateway: @Bean RouteLocator gateway(RouteLocatorBuilder rlb) { return rlb. routes() .route( route -> route.path(“/customers”) .uri(“lb://customers/”) ) .build(); }
if i go to localhost:9999/customers l will move to my:customer:service/customers and its works for me. summary what i changed: prefer-ip-adress and hostname. It works for me. I spend about a day to solve it, hope it will help
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.