Eureka server and eureka client to separate tomcat servers - spring

I'm looking for a way to be able to deploy the Eureka server to a different tomcat server than the Eureka client.
this is the client application.yml:
eureka:
client:
registryFetchIntervalSeconds: 5
instance:
preferIpAddress: true
leaseRenewalIntervalInSeconds: 10
server:
port: 8080
spring:
application.name: my-client
jmx:
default-domain: my-client
and the server application.yml looks like:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
It works perfectly fine if I deploy them to the same tomcat-server. But if I start the tomcat with the server only and later start the server with the client, I get the following error:
2017-03-09 16:17:58.496 INFO 7693 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2017-03-09 16:17:58.496 INFO 7693 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2017-03-09 16:17:58.496 INFO 7693 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2017-03-09 16:18:04.740 WARN 7693 --- [on(2)-127.0.0.1] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with status code 404; retrying on another server if available
2017-03-09 16:18:04.745 ERROR 7693 --- [on(2)-127.0.0.1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MYCLIENT-CLIENT/192.168.196.141:my-client:8080 - was unable to refresh its cache! status = Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111) ~[eureka-client-1.4.12.jar:1.4.12]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.4.12.jar:1.4.12]
What is the difference between bootstrap.yml and application.yml?
Any help would be appreciated!

your client application.yml dosen't have information about where your eureka server is running.client should register with eureka server, for that you need to configure your client application.yml as follow
eureka:
client:
serviceUrl:
defaultZone:http:localhost:8081/eureka/
instance:
instanceId:application_name:${random.value}

Related

spring boot application properties not read correctly

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

Zuul -> Eureka Server, Basic Authentication issue

I am able to hit the service, if the flow doesn't contain Basic Authorization.
If i use Basic Authorization, it throws "message": "Full authentication is required to access this resource"
Below are my observations:
In ZuulFilter, run() method, i get value for
request.getHeader("Authorization") --> Basic c29tOnNvbzz==
but once it reaches the Micro Service, i am getting value as 'null',
request.getHeader("Authorization") --> null
Using Spring Boot version : 1.4.0.RELEASE
This is my flow:
------------------
Zuul -> Service Discovery (Eureka Server) -> Service
Kindly help, not sure where the Authorization header is vanishing.
Eureka Server yml file:
-------------------------
server.port:4001
eureka.instance.hostname=localhost
eureka.client.fetch-registry:false
eureka.client.register-with-eureka:false
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.client.healthcheck.enabled=true
Zuul yml file:
-----------------
server:
port: 8765
info:
component: Edge Server
eureka:
instance:
leaseRenewalIntervalInSeconds: 3
metadataMap:
instanceId: ${spring.application.name}:${random.value}
client:
# Default values comes from org.springframework.cloud.netflix.eurek.EurekaClientConfigBean
registryFetchIntervalSeconds: 5
instanceInfoReplicationIntervalSeconds: 5
initialInstanceInfoReplicationIntervalSeconds: 5
endpoints:
restart:
enabled: true
shutdown:
enabled: true
health:
sensitive: false
zuul.sensitive-headers: Cookie,Set-Cookie,Authorization
logging:
level:
ROOT: WARN
se.callista: INFO
# Get info regarding connection to the cofig server and retries if required
org.springframework.cloud.config.client.ConfigServicePropertySourceLocator: INFO
org.springframework.retry.support.RetryTemplate: DEBUG
# Set INFO to see the allocated port
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer: INFO
---
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:4001/eureka,http://localhost:4002/eureka
Authorization is by default a sensitive header, this means Zuul will not forward them. If you leave it out of the sensitive headers, Zuul will forward the header.
zuul.sensitiveHeaders: Cookie,Set-Cookie
It should also be camelCase instead of hyphenated.
Extra info: https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers
This solved my problem, but is this the only solution we have ?
ctx.addZuulRequestHeader("Authorization",request.getHeader("‌​Authorization"))
Your property for zuul.sensitiveHeaders is wrong. It is camel case not hyphenated.
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#cookies-and-sensitive-headers

SpringBoot App Registers UNKNOWN with Eureka in Brixton SR3

I'm running Spring Cloud Brixton SR3 - Spring Netflix Eureka, Spring Cloud Config and a Discovery Client app. When the client app is configured with
eureka.client.healthcheck.enabled=true
and
spring.cloud.config.discovery.enabled=true
the app starts up registered with Eureka with a status of "UNKNOWN" and never changes to "UP". If either of those flags is set to false then the app starts up registered as "UP".
I see this series of logging when both flags are enabled/true:
2016-07-13 17:41:38.144 INFO 13180 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1468456898144, current=UP, previous=STARTING]
2016-07-13 17:41:38.144 DEBUG 13180 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : Executing on-demand update of local InstanceInfo
2016-07-13 17:41:38.144 DEBUG 13180 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : Canceling the latest scheduled update, it will be rescheduled at the end of on demand update
2016-07-13 17:41:38.145 INFO 13180 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1468456898145, current=UNKNOWN, previous=UP]
How do I get the app to register as UP with both of these flags enabled/true?
bootstrap.yml
spring:
application:
name: hello-brixton
# Spring Cloud Config
cloud:
config:
name: hello-brixton
discovery:
enabled: true
serviceId: config-service
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: ${SERVICE_REGISTRY_URL:http://localhost:8080/eureka/}
healthcheck:
enabled: true
I know this was asked a long time ago, but I just ran into the same problem and this was the only questions that directly matched my issue.
I am using Camden.SR2, and if you find the section Eureka’s Health Checks in the reference documentation you will see the following warning:
eureka.client.healthcheck.enabled=true should only be set in
application.yml. Setting the value in bootstrap.yml will cause
undesirable side effects like registering in eureka with an UNKNOWN
status.
That's exactly the problem. If you shift the setting of the property to the application.yml file it all works as expected.

In Eureka First Bootstrap mode if client starts on a random port number, its registring with port 0

I'm using spring cloud Brixton.M4 and spring boot is v1.3.1, with eureka first approach and application starts on random port server.port=0 but its register it self at port 0 with eureka server.
here is my bootstrap.properties file
server.port=0
spring.application.name=course-composite-service
spring.cloud.config.fail-fast=true
spring.cloud.config.label=config-dev
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
eureka.client.serviceUrl.defaultZone=http://localhost:8002/eureka/
and below its the log
2016-01-11 18:36:50.286 INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0: registering service...
2016-01-11 18:36:50.288 INFO 17233 --- [ main] .w.c.c.CourseCompositeServiceApplication : Started CourseCompositeServiceApplication in 5.325 seconds (JVM running for 5.856)
2016-01-11 18:36:50.321 INFO 17233 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COURSE-COMPOSITE-SERVICE/192.168.17.178:course-composite-service:0 - registration status: 204
and eureka dashboard shows
COURSE-COMPOSITE-SERVICE UP (1) - 192.168.17.178:course-composite-service:0
why its not registering with the actual port its running?
i'm providing other eureka configurations from the Config Sever they are
eureka.client.register-with-eureka=true
eureka.instance.leaseRenewalIntervalInSeconds=10
eureka.instance.leaseExpirationDurationInSeconds=5
eureka.instance.preferIpAddress=false
eureka.instance.metadataMap.hostname=${vcap.application.application_uris[0]}
eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}

Using Hystrix Stream in Zuul with Eureka First to find Config server

I'm using spring cloud Brixton.M4 with spring boot 1.3.1
I have zuul server with
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
and i'm using Eureka first to find Config-Server so bootstrap looks like
spring:
profiles: dev
cloud:
config:
fail-fast: true
discovery:
enabled: true
serviceId: config-server
zuul is registring two time first with UP state then with STARTING
2016-01-18 14:47:27.209 INFO 2808 --- [ main] c.w.i.edgeserver.EdgeServerApplication : Started EdgeServerApplication in 21.651 seconds (JVM running for 22.232)
2016-01-18 14:47:56.231 INFO 2808 --- [ool-20-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EDGE-SERVER/192.168.17.178:edge-server:8003 - Re-registering apps/EDGE-SERVER
2016-01-18 14:47:56.270 INFO 2808 --- [ool-20-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EDGE-SERVER/192.168.17.178:edge-server:8003: registering service...
2016-01-18 14:47:56.281 INFO 2808 --- [ool-20-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EDGE-SERVER/192.168.17.178:edge-server:8003 - registration status: 204
2016-01-18 14:48:06.230 INFO 2808 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EDGE-SERVER/192.168.17.178:edge-server:8003: registering service...
2016-01-18 14:48:06.238 INFO 2808 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EDGE-SERVER/192.168.17.178:edge-server:8003 - registration status: 204
If I remove dependency on config-server by setting
spring:
profiles: dev
cloud:
config:
fail-fast: false
discovery:
enabled: false
serviceId: config-server
everything runs fine.
That's normal I think (the bootstrap phase has to register to get the configserver location, and then unregister to let the main application register again). You will probably find that it settles back to UP after the application has started up fully.

Resources