For some reason it does not seem like application.yml is correctly read in my spring boot application. No matter what I try with the application tries to connect to eureka on local host.
spring:
application:
name: oneminute-dashboard
server:
port: 5001
eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka
sql:
init:
platform: postgres
datasource:
url: jdbc:postgresql://db:5432/dev_onemin_percent
username: xxxx
password: xxxx
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.PostgreSQLDialect
Looking at the log I see that it tries to connect to localhost. I have the same problem with postgres but there the datasource can be overridden from the docker-compose file.
oneminute_dashboard | 2022-08-02 10:09:58.069 WARN 1 --- [ restartedMain] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
oneminute_dashboard | 2022-08-02 10:09:58.069 INFO 1 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ONEMINUTE-DASHBOARD/01bd8154c292:oneminute-dashboard:5001 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
docker compose below
version: '3.8'
services:
oneminute_dashboard:
image: xyz/oneminute_dashboard:latest
container_name: oneminute_dashboard
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/dev_onemin_percent
ports:
- "5001:5001"
expose:
- 5001
networks:
- IB
depends_on:
- eureka-server
This documentation uses serviceUrl instead of service-url
https://cloud.spring.io/spring-cloud-static/Edgware.SR6/multi/multi__service_discovery_eureka_clients.html
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
It will be
default-zone: http://eureka-server:8761/eureka
and not
defaultZone: http://eureka-server:8761/eureka
Related
I'm following this "Microservices with Spring Boot and Spring Cloud" book by Magnus Larsson, at chapter 10 Spring Cloud Gateway is introduced as an edge server into the microservices landscape, once all the microservices are started SCGateway is unable to connect with the Eureka server:
RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://eureka:8761/eureka/}, exception=I/O error on POST request for "http://eureka:8761/eureka/apps/GATEWAY": Connect to eureka:8761 [eureka/172.23.0.4] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eureka:8761 [eureka/172.23.0.4] failed: Connection refused stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://eureka:8761/eureka/apps/GATEWAY": Connect to eureka:8761 [eureka/172.23.0.4] failed: Connection refused; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to eureka:8761 [eureka/172.23.0.4] failed: Connection refused...
this is the docker-compose.yml file:
version: '2.1'
services:
product:
...instance configuration
recommendation:
...instance configuration
review:
...instance configuration
product-composite:
...instance configuration
mongodb:
...instance configuration
mysql:
...instance configuration
rabbitmq:
...instance configuration
eureka:
build: spring-cloud/eureka-server
mem_limit: 512m
gateway:
environment:
- SPRING_PROFILES_ACTIVE=docker
build: spring-cloud/gateway
mem_limit: 512m
ports:
- "8085:8085"
Eureka Dockerfile:
FROM adoptopenjdk:16_36-jre-hotspot as builder
WORKDIR extracted
ADD ./build/libs/*.jar app.jar
RUN java -Djarmode=layertools -jar app.jar extract
FROM adoptopenjdk:16_36-jre-hotspot
WORKDIR application
COPY --from=builder extracted/dependencies/ ./
COPY --from=builder extracted/spring-boot-loader/ ./
COPY --from=builder extracted/snapshot-dependencies/ ./
COPY --from=builder extracted/application/ ./
EXPOSE 8761
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
Eureka application.yml file:
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# from: https://github.com/spring-cloud-samples/eureka/blob/master/src/main/resources/application.yml
server:
waitTimeInMsWhenSyncEmpty: 0
response-cache-update-interval-ms: 5000
management.endpoints.web.exposure.include: "*"
Spring Cloud Gateway Dockerfile:
FROM adoptopenjdk:16_36-jre-hotspot as builder
WORKDIR extracted
ADD ./build/libs/*.jar app.jar
RUN java -Djarmode=layertools -jar app.jar extract
FROM adoptopenjdk:16_36-jre-hotspot
WORKDIR application
COPY --from=builder extracted/dependencies/ ./
COPY --from=builder extracted/spring-boot-loader/ ./
COPY --from=builder extracted/snapshot-dependencies/ ./
COPY --from=builder extracted/application/ ./
EXPOSE 8085
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
Spring Cloud Gateway application.yml file:
server.port: 8085
spring.application.name: gateway
app.eureka-server: localhost
eureka:
client:
serviceUrl:
defaultZone: http://${app.eureka-server}:8761/eureka/
initialInstanceInfoReplicationIntervalSeconds: 5
registryFetchIntervalSeconds: 5
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
spring.cloud.gateway.routes:
- id: product-composite
uri: lb://product-composite
predicates:
- Path=/product-composite/**
- id: product-composite-swagger-ui
uri: lb://product-composite
predicates:
- Path=/openapi/**
- id: eureka-api
uri: http://${app.eureka-server}:8761
predicates:
- Path=/eureka/api/{segment}
filters:
- SetPath=/eureka/{segment}
- id: eureka-web-start
uri: http://${app.eureka-server}:8761
predicates:
- Path=/eureka/web
filters:
- SetPath=/
- id: eureka-web-other
uri: http://${app.eureka-server}:8761
predicates:
- Path=/eureka/**
management.endpoint.health.show-details: "ALWAYS"
management.endpoints.web.exposure.include: "*"
logging:
level:
root: INFO
org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator: INFO
org.springframework.cloud.gateway: TRACE
---
spring.config.activate.on-profile: docker
app.eureka-server: eureka
Originally the project uses Spring Boot version 2.5.2 and Spring Cloud version 2020.0.3, also tried with recent versions (with no success) such as:
Spring Boot version: 2.6.6 and 2.7.5
Spring Cloud: 2021.0.4
The Spring Cloud Gateway is always throwing the same exception:
org.apache.http.conn.HttpHostConnectException: Connect to eureka:8761
[eureka/172.23.0.4] failed: Connection refused
Trying to access the Eureka dashboard or http://localhost:8085/actuator/health endpoint hangs forever.
I'll appreciate any hints or help, thanks in advance.
I have microservices application, and i'm using Spring cloud and Spring boot v2.3 . i'm depending on config server and eureka, everything is working fine on my local machine from IDE, but when I deployed the stack on docker, my app Auth-Service cannot fetch from spring config server container, and give me the following stack trace
2020-07-05 02:23:52.888 INFO [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-07-05 02:23:53.091 INFO [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-07-05 02:23:53.092 WARN [auth-service,,,] 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/auth-service/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
I thought the issue is just waiting until or container-network as mentioned here Spring config is no accessible and this Microservices can't reach config service, but I ensured the containers are within same network, and to simulate, I started the config first, but got same error.
Here are the configurations i'm using
version: '3.8'
services:
eureka-service:
build:
context: ./eureka
image: eureka-service:latest
container_name: eureka
ports:
- 8761:8761
hostname: eureka
networks:
- mynetwork
config-service:
build:
context: ./configServer
image: config-server:latest
ports:
- 8888:8888
networks:
- mynetwork
proxy-service:
build:
context: ./web-cv-proxy
image: zuul-service:latest
ports:
- 8081:8081
depends_on:
- config-service
networks:
- mynetwork
auth-service:
build:
context: ./web-based-cv/auth-service
image: auth-service:latest
ports:
- 8060:8060
depends_on:
- config-service
- eureka-service
restart: on-failure
networks:
- mynetwork
portal-service:
build:
context: ./web-based-cv/cv-portal
image: cv-portal:latest
ports:
- 9090:9090
depends_on:
- config-service
- eureka-service
restart: on-failure
networks:
- mynetwork
networks:
mynetwork:
driver: bridge
Config server docker file
FROM java:openjdk-8-alpine
LABEL version="1.0"
LABEL description="configuration server"
COPY ./target/configServer-0.0.1-SNAPSHOT.jar ./
EXPOSE 8888
CMD ["java", "-jar", "configServer-0.0.1-SNAPSHOT.jar"]
Application docker file
FROM java:openjdk-8-alpine
LABEL version="1.0"
LABEL description="cv authintication service"
COPY ./target/auth-service-1.0.0-exec.jar auth-service-1.0.0-exec.jar
EXPOSE 8060
CMD ["java", "-jar", "/auth-service-1.0.0-exec.jar"]
The application bootstrap file
spring:
datasource:
jpa:
properties:
hibernate:
format_sql: true
ddl-auto: none
application:
name: auth-service
bus:
refresh:
enabled: true
profiles:
active: jdbc
cloud:
retry:
initial-interval: 1500
multiplier: 1.5
max-attempts: 10000
max-interval: 1000
server:
servlet:
context-path: /api/auth
port: 8060
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: true
instance:
prefer-ip-address: true
management:
endpoints:
web:
exposure:
include: ["health","info","refresh", "bus-refresh"]
Your advice is highly appreciated , and thanks in advance.
Remember one thing, when you deploy your micro-services on docker,
localhost won't work there as your micoservices run in a container
within a different virtual network. So it won't be identified using
localhost.
So in your docker compose file, you have to provide the name of your
the service of your Eureka server.
For example -
services:
discovery:
image: <Eureka server image name>
ports:
- 8761:8761
ConfigServerService:
image: <Config server image name>
environment:
- JAVA_OPTS=
-DEUREKA_SERVER=http://discovery:8761/eureka
depends_on:
- discovery
links:
- discovery
ports:
- 8888:8888
Microservice1:
image: <Microservice1 image name>
environment:
- JAVA_OPTS=
-DEUREKA_SERVER=http://discovery:8761/eureka
depends_on:
- discovery
- ConfigServerService
links:
- discovery
- ConfigServerService
ports:
- 8000:8000
You need to change auth-service configuration from localhost:8888 to http://config-service:8888, as the error seems not getting the correct endpoint.
docker-compose networking
error on GET request for "http://localhost:8888/auth-service/default": Connection refused (Connection refused);
localhost:8888 means this container (auth-service) not the spring config server.
For some reason my containers didn't be able to connect using direct uri configuration, although I added them to the same network.
I solved the issue with depending on Eureka itself, and connecting to Spring config through eureka discovery with the following config in client apps
spring
config:
discovery:
enabled: true
service-id: configServer
I think it is a good way to give the control to eureka, but I hoped i would know why it didn't work with uri instead? by the way this way will give me more flexibility if I deployed on several clusters.
We have developed Spring-boot microservices with NetFlix OSS/Spring-cloud. In the development environment, we are running with embedded tomcat, it works well.
Now I'm trying to deploy on Weblogic 12.1.2, I'm able to deploy service registry and API-Gateway inside two different managed servers. But When I open Eureka server page, API-Gateway is not registered with the Service Registry.
Service-Registry application.yml
spring:
application:
name: service-registry
server:
port: 61001
eureka:
client:
register-with-eureka: false
fetch-registry: false
api-gateway application.yml
spring:
application:
name: api-gateway
cloud:
loadbalancer:
retry:
enabled: true
# Ribbon - Client side load balancer
ribbon:
ReadTimeout : 60000
ConnectTimeout: 60000
server:
port: 61002
context-path: /nasw
eureka:
client:
serviceUrl:
defaultZone: http://<ipAdr>:61001/eureka/
# instance:
# instanceId:
### Zuul - Router/Filter/Reverse Proxy
zuul:
ignoredServices: '*'
host:
connect-timeout-millis: 100000
socket-timeout-millis: 600000
routes:
network-planning: "**/network-planning/**"
network-schemagen: "**/network-schemagen/**"
network-verification: "**/network-verification/**"
nw-netgeoview-nw-tracer: "**/nw-netgeoview-nw-tracer/**"
### Hystrix - Circuit Breaker/Fault&Latency Tolerant
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 600000
timeout:
enabled: false
isolation:
strategy: SEMAPHORE
Service registry home page
Could you please help me with following queries?
Is it possible to deploy Spring-Cloud on Weblogic 12.1.2?
Is it a correct way to deploy each microservice in a separate managed server?
If Yes, Am I missing any configuration so that api-gateway can register with service-registry?
I have a spring-boot application which I use to setup a spring cloud config server and a eureka server in development and testing environments.
Strangely the application always tries to connect to localhost:8761, even though I have eureka.client.registerWithEureka set to false.
How can I deactivate this?
The error:
ERROR 3144 --- [et_localhost-12] c.n.e.cluster.ReplicationTaskProcessor : Network level connection to peer localhost; retrying after delay
com.sun.jersey.api.client.ClientHandlerException: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.4.10.jar:1.4.10]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.4.10.jar:1.4.10]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.4.10.jar:1.4.10]
at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:71) ~[eureka-core-1.4.10.jar:1.4.10]
at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.4.10.jar:1.4.10]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
My only class looks like this:
#EnableEurekaServer
#EnableConfigServer
#SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
The application.yml:
server:
port: 8888
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
renewal-percent-threshold: 0.49
security:
basic:
enabled: true
user:
password: mypassword
spring:
jmx:
default-domain: ${spring.application.name}
cloud:
config:
server:
git:
uri: https://example.com/myrepo.git
username: username
password: password
clone-on-start: true
search-paths: '{application},{application}/{profile}'
endpoints:
jmx:
domain: ${spring.application.name}
unique-names: true
In the bootstrap.yml I have only the application name set.
Versions:
spring-cloud-netflix-eureka: 1.1.6,
spring-cloud-config-server: 1.1.3
Could you try to change your configuration like below
eureka:
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://localhost:8888/eureka
You specify server.port: 8888. So your eureka is running on 8888 port. But you didn't specify any service-url for eureka. So I think that your eureka server is trying to replicate to localhost:8761 because it's default and you didn't specify service-url for eureka.
For me, below properties that worked for me.
eureka.client.registerWithEureka= false
eureka.client.fetchRegistry= false
eureka.server.maxThreadsForPeerReplication=0
Please Use 8761 port for your Eureka server as below.
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
Here we’re configuring an application port – 8761 is the default one for Eureka servers. We are telling the built-in Eureka Client not to register with ‘itself’, because our application should be acting as a server.
It seems that eureka tries to connect to itself despite the below settings:
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
you have two options to fix that 1-Keep the default port of eureka 2-Add below to your application.properties of your eureka server eureka.server.maxThreadsForPeerReplication=0
I'm facing a ZuulException: forward error when routing with Zuul and Eureka.
The error not occur during the first minutes but after 1 or 2 mn I get this weird error.
I'm using spring boot 1.4 and spring cloud Camden
If you want to reproduce the error or see my project: https://github.com/Seb69/Spring-demo-ZuulException/tree/master
Eureka config:
server:
port: 9999
spring:
application:
name: eureka-server
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Service-Gateway config (Zuul):
server:
port: 1111
spring:
application:
name: service-gateway
# ZUUL (Load balancing)
zuul:
ignoredServices: '*'
routes:
service-server:
stripPrefix: true
path: /api/**
serviceId: SERVICE-SERVER
# EUREKA (Service registry)
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:9999/eureka/
Service config:
server:
port: 8095
spring:
application:
name: service-server
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:9999/eureka/
Here is a short version of my stack trace:
com.netflix.zuul.exception.ZuulException: Forwarding error
Caused by: com.netflix.client.ClientException: Number of retries on
next server exceeded max 1 retries, while making a call for:
mbp-de-andre:8095
Caused by: java.net.UnknownHostException: mbp-de-andre
FIX:
So, I finaly succeed to make it work !
My problem came from my Macbook Hostname,
Last hostname was: mbp-de-andre
I modify it and I set: `MacBook-Pro-de-ANDRE.local``
Just want to say another fix might be missing dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>