spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.55k stars 3.33k forks source link

Spring Cloud Gateway not able to resolve routes and gives error code 500 #1572

Closed Abhinav-401 closed 4 years ago

Abhinav-401 commented 4 years ago

Hi, I am following a tutorial on spring cloud gateway and netflix eureka: https://www.javainuse.com/spring/cloud-gateway-eureka

My config file for gateway is:

`server:`
  port: 9090

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka              

spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      routes:
      - id: employeeModule
        uri: lb://FIRST-SERVICE
        predicates:
        - Path=/employee/**
      - id: consumerModule
        uri: lb://SECOND-SERVICE
        predicates:
          - Path=/consumer/**)

1

Gateway and both the services have been registered with eureka. But, now, if I try to open something like: http://host.docker.internal:9090/employee/message OR http://localhost:9090/employee/message (Same), then I'm getting error 500. The stack trace is:


2020-02-13 12:49:01.713  INFO 25664 --- [           main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9090
2020-02-13 12:49:01.739  INFO 25664 --- [           main] com.javainuse.APIGatewayApplication      : Started APIGatewayApplication in 9.385 seconds (JVM running for 9.81)
2020-02-13 12:49:26.857  INFO 25664 --- [ctor-http-nio-2] c.netflix.config.ChainedDynamicProperty  : Flipping property: FIRST-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2020-02-13 12:49:26.896  INFO 25664 --- [ctor-http-nio-2] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-FIRST-SERVICE
2020-02-13 12:49:26.896  INFO 25664 --- [ctor-http-nio-2] c.netflix.loadbalancer.BaseLoadBalancer  : Client: FIRST-SERVICE instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=FIRST-SERVICE,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2020-02-13 12:49:26.931  INFO 25664 --- [ctor-http-nio-2] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2020-02-13 12:49:26.997  INFO 25664 --- [ctor-http-nio-2] c.netflix.config.ChainedDynamicProperty  : Flipping property: FIRST-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2020-02-13 12:49:26.999  INFO 25664 --- [ctor-http-nio-2] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client FIRST-SERVICE initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=FIRST-SERVICE,current list of Servers=[host.docker.internal:8080],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:1;       Active connections count: 0;    Circuit breaker tripped count: 0;       Active connections per server: 0.0;]
},Server stats: [[Server:host.docker.internal:8080;     Zone:defaultZone;       Total Requests:0;       Successive connection failure:0;        Total blackout seconds:0;       Last connection made:Thu Jan 01 05:30:00 IST 1970;      First connection made: Thu Jan 01 05:30:00 IST 1970;   Active Connections:0;   total failure count in last (1000) msecs:0;     average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;      max resp time:0.0;      stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@40a6cdda
2020-02-13 12:49:27.956  INFO 25664 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty  : Flipping property: FIRST-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2020-02-13 12:49:48.107 ERROR 25664 --- [ctor-http-nio-7] a.w.r.e.AbstractErrorWebExceptionHandler : [5fe5e1a0] 500 Server Error for HTTP GET "/employee/message"

io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: host.docker.internal/10.7.250.57:8080
Caused by: java.net.ConnectException: Connection timed out: no further information
        at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:579) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:820) ~[na:na]
        at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:336) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:685) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]

I'm able to access localhost:8080/employee/message and localhost:8082/consumer/message without any problem. Can someone tell me what the problem here is? Is there something wrong with the config. Also, if I put the address in the config instead of the service name, then it's working fine.

imeshkov commented 4 years ago

I have same problem. What the way resolve this problem?

Abhinav-401 commented 4 years ago

Do you have docker installed on your system? If yes,then I changed host.docker.internal property to 127.0.0.1. Search the system for drivers folder. I don't remember the path after this. (WINDOWS)

If docker is not installed, then your services are not being initialized properly. I don't have the solution for this.

On Tue, Feb 18, 2020, 17:50 imeshkov notifications@github.com wrote:

I have same problem. What the way resolve this problem?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-gateway/issues/1572?email_source=notifications&email_token=AMYSDUBC42QC2AAKWNAMGSTRDPHBZA5CNFSM4KUMIPI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMBYPUI#issuecomment-587433937, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMYSDUGGOL2PKVDPTOK2SHTRDPHBZANCNFSM4KUMIPIQ .

imeshkov commented 4 years ago

Yes, the problem was in the installed docker. I changed host.docker.internal property to 127.0.0. . It's works. Thanks.

Abhinav-401 commented 4 years ago

No problem

On Tue, Feb 18, 2020, 21:01 imeshkov notifications@github.com wrote:

Yes, the problem was in the installed docker. I changed host.docker.internal property to 127.0.0. . It's works. Thanks.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-gateway/issues/1572?email_source=notifications&email_token=AMYSDUBPDUEH2JP7GRFSE4TRDP5NTA5CNFSM4KUMIPI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMCNPIY#issuecomment-587519907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMYSDUC2AWP7Q2DCUGOX6ADRDP5NTANCNFSM4KUMIPIQ .

gsanthoshvarma commented 3 years ago

Hey guys, i have same problem too, my spring cloud gateway unable to find actual microservice. what url should i use from my gateway. tried : http://127.0.0.1:8080/user-service/hello/ <-- not working http://host.docker.internal:8080/loan-service/hello <-- not working.

Saoudyahya commented 6 months ago

yo what is the solutions