I am using Java 21 and Spring Boot 3.3.0(RC1).
I have made one user microservice. Its application.yaml file looks something like this
server:
port: 5001
spring:
application:
name: USER-SERVICE
datasource:
url: #
username: #
password: #
jpa:
hibernate:
ddl-auto: update
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://localhost:8081/eureka/
I have made an Eureka server and the above microservice is registered to this server as well.
The application.yaml for this server is:
server:
port: 8081
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
I made a cloud gateway using the Reactive gateway dependency to route all microservice endpoints from here.
The application.yaml file is:
spring:
application:
name: GATEWAY-SERVICE
cloud:
gateway:
routes: #setup paths here
- id: USER-SERVICE
uri: lb://USER-SERVICE
predicates:
- Path=/auth/**, /api/user/**
default-filters: #setup cors here
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
globalcors: #setup cors here
cors-configurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
server:
port: 6500
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true
register-with-eureka: true
serviceUrl:
defaultZone: http://localhost:8081/eureka/
This gateway is also registered with the Eureka server. Now, when I go to http://localhost:8081
, I can see two microservices, one for user service
and another for gateway
are coming up and they are UP
.
Their status looks like this:
192.168.1.4:USER-SERVICE:5001
192.168.1.4:GATEWAY-SERVICE:6500
Now, when I hit http://localhost:6500/auth/login
from Postman, I get a 500 error and there are no errors in the user service console, but there is an error in the gateway service.
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: /192.168.1.4:5001
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 POST "/auth/login" [ExceptionHandlingWebHandler]
Original Stack Trace:
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:682) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973) ~[na:na]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.109.Final.jar:4.1.109.Final]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
When I hit http://localhost:5001/auth/login
in Postman, I get the proper response.
This complete setup is running on my local machine. I am unable to figure this out, and I need help. If you need any other code, I can add it.
My antivirus firewall was not allowing any connection, so if you get this error, disable firewall from antivirus and try again, it will work.