I have 6 spring boot projects:
- rabbitmq
- configserver
- discrovery
- apigateway (zuul)
- users-ms
- business-ms
When I run these applications natively on my computer everything works fine. I need to dockerize these apps to form microservice architecture. I adopted the properties files for a profile, called "dockertest".
I start containers in the following order (without docker compose):
docker run -d --network test-net --hostname rabbitmq-service --name rabbitmq-service -p 4369:4369 -p 5671:5671 -p 5672:5672 -p 15671:15671 -p 15672:15672 -p 25672:25672 rabbitmq-service
docker run -d --network test-net --hostname configserver --name configserver -p 8888:8888 -e "SPRING_PROFILES_ACTIVE=dockertest" configserver
docker run -d --network test-net --hostname discrovery --name discrovery -p 8710:8710 -e "SPRING_PROFILES_ACTIVE=dockertest" discrovery
docker run -d --network test-net --hostname apigateway --name apigateway -p 8770:8770 -e "SPRING_PROFILES_ACTIVE=dockertest" apigateway
docker run -d --network test-net --hostname users-ms --name users-ms -P -e "SPRING_PROFILES_ACTIVE=dockertest" users-ms
...and the problem starts here.
discrovery service is not depend on config server, so it starts fine.
apigateway is depend on configserver, but everything is ok, gets configs and starts fine.
user-ms is also depend on configserver, but the connection hangs out and after a long time throws read timeout exception and exits.
user-ms sees configserver (i think), because if I set wrong configserver params voluntarily the service immediately exits (fail-fast=true).
Do you have any idea how can I solve this problem?
---- Update ----
I paste here the relevant configuration and Dockerfiles:
Every services depend on configserver have these configuration to reach configserver:
spring.config.import=configserver:
spring.cloud.config.uri=http://configserver:8888
spring.cloud.config.username=...
spring.cloud.config.password=...
spring.cloud.config.fail-fast=true
configserver
FROM openjdk:13-alpine
ADD /target/configserver-service-0.0.1-SNAPSHOT.jar app.jar
ADD /healthcheck.sh healthcheck.sh
RUN chmod 777 /healthcheck.sh
RUN mkdir /tmp/tomcat static
EXPOSE 8888
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
apigateway It starts fine, connects to configserver and gets configs.
FROM openjdk:13-alpine
ADD /target/apigateway-service-0.0.1-SNAPSHOT.jar app.jar
ADD /healthcheck.sh healthcheck.sh
RUN chmod 777 /healthcheck.sh
RUN mkdir /tmp/tomcat static
EXPOSE 8770
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
users-ms This one exits after long time (default timeout in spring.config.request_timeout is 185000 and requset_connection_timeout is 1000)by throwing read timeout exception.
FROM openjdk:13-alpine
ADD /target/users-service-0.0.1-SNAPSHOT.jar app.jar
ADD /healthcheck.sh healthcheck.sh
RUN chmod 777 /healthcheck.sh
RUN mkdir /tmp/tomcat static
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
The read timeout exception what I get (there is no any other logs in docker desktop console (mac), futhermore the log screen is empty during this hangout period):
15:39:14.816 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:148)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:84)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:59)
at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:102)
at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:118)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:82)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:119)
at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:294)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:223)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:88)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:80)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.xyz.ms..api.users.XYZUsersServiceApplication.main(XYZUsersServiceApplication.java:16)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://configserver:8888/users-ws/dockertest": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:784)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:710)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:601)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.getRemoteEnvironment(ConfigServerConfigDataLoader.java:250)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:100)
... 35 common frames omitted
Caused by: java.net.SocketTimeoutException: Read timed out
at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:284)
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:310)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:351)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:802)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:919)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:245)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:285)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:344)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:746)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1610)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:82)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:775)
... 39 common frames omitted
-----Update: solution -----
It's not too sexy. To check myself, I went back to native (host) platform and tried to start everything to make sure its running. And it didn't. It's suprise me. I use Intellij and Spring Boot 2.4.1. I thought something messed up, so I check spring initilzr for the proper settings in pom file again, and cleared the cache of IntelliJ, and this did the trick. Everything works now. Thanks for your time!