Spring Cloud Gateway unable to resolve Eureka DNS

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:22 (3 by maintainers)

github_iconTop GitHub Comments

19reactions
NikitaStrigacommented, Mar 13, 2021

hello 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

15reactions
EGo14Tcommented, Jan 27, 2021

eureka.instance.hostname=localhost add this config to your microservice

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring cloud gateway unable to resolve service id from eureka ...
To enable this, set spring.cloud.gateway.discovery.locator.enabled=true and make sure a DiscoveryClient implementation is on the classpath and ...
Read more >
Spring Cloud configuration properties
The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way...
Read more >
Spring Gateway can't resolve DNS name of local computer
Spring Gateway can't resolve DNS name of local computer. Hello there. So I'm trying to use a Spring Gateway that contacts a Spring...
Read more >
Introduction to Spring Cloud Netflix - Eureka - Baeldung
Implementing a Eureka Server for service registry is as easy as: ... Let's do it step by step. ... We can check the...
Read more >
[Solved]-Spring Cloud Gateway Kubernetes Eureka java.net ...
[Solved]-Spring Cloud Gateway Kubernetes Eureka java.net.UnknownHostException: failed to resolve-Springboot ... You can workaround this by using IP address: set ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found