*****Config Server- Application Service Setup*****
Below is the configuration from application.yml
server:
port: 8882
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
cloud:
config:
server:
git:uri: https://github.com/appleman/config
Below is the configuration from boostrap.yml
spring:
application:
name: configserver
Starting of this plain spring boot application registers config-server to Eureka.
**General Eureka Server is running on 8761 port
********Below is the Application Client configuration*****
Below is the Application Client configuration in my bootstrap.yml
spring:
application:
name: contractService,envDEV13
cloud:
config:
enabled: true
discovery:
enabled: true
serviceId: configserver
eureka:
instance:
nonSecurePort: ${server.port:8080}
client:
serviceUrl:
defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/
Injection of properties in Spring Controller like the below snippet is not working.
#Value("${creditService.eppDbUrl}")
String bar;
Please suggest us if we are doing anything wrong.
Related
i'm trying to add Spring Boot Admin to my Eureka Server, but it looks like there is something wrong somewhere.
I'm using
Spring Boot version 2.1.5.RELEASE (starter parent)
spring-cloud-starter-netflix-eureka-server
spring-boot-admin-starter-server
My Main Class is annotated with
#SpringBootApplication
#EnableAdminServer
#EnableEurekaServer
And this is the application.yml
spring:
application:
name: eureka-server
boot:
admin:
context-path: /admin
security:
basic:
enabled: false
management:
security:
enabled: false
eureka:
client:
register-with-eureka: false
fetch-registry: true
instance:
leaseRenewalIntervalInSeconds: 15
After i started the server, i try to launch a microservice
The application.yaml go the client is the following:
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
leaseExpirationDurationInSeconds: 5
client:
service-url:
default-zone: http://localhost:8761/eureka
healthcheck:
enabled: true
lease:
duration: 5
management:
endpoints:
web:
exposure:
include: '*'
security:
enabled: false
but i see it in eureka as down
and i cannot see anything in SBA
I have a Eureka Server running on default localhost host and port 8761, so i tried to change this default configuration in this way:
server:
port: 6000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
But in this way i can't access eureka dashboard, just using default configuration:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
In my client same thing occurrs, i can't point to another eureka server different from default (localhost:8761), see my configuration:
server:
port: 7000
servlet:
context-path: /client-eureka
spring:
application:
name: client-eureka
eureka:
instance:
prefer-ip-address: true
client:
eureka-server-port: 6000
eureka-server-u-r-l-context: /myeureka
Lookin in client log i got the following:
2018-09-01 09:19:37.175 INFO 4931 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : Replica node URL: http://localhost:8761/eureka/
No matter what port or host i configure in client, always try to reach the default.
Important:
I'm using eureka in this version: https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server/2.0.1.RELEASE
I used the same dependency version as yours and cannot find the config path server.servlet.contextpath
Instead, you can use either server.servlet-path or server.context-path
With each of the server configuration, you need to update your client application.yml file too. Remember that /eureka is the default REST endpoint used to register Eureka client with Eureka server
Case 1: Use server.servlet-path
Eureka Server:
server:
port: 7000
servlet-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka Client:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/eureka}
instance:
preferIpAddress: true
Case 2: Use server.context-path
Eureka Server:
server:
port: 7000
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka Client:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:7000/myeureka/eureka}
instance:
preferIpAddress: true
Updated answer:
Because server.servlet-path and server.context-path were deprecated, eureka server will be configured as following:
server:
port: 7000
servlet:
context-path: /myeureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka client application.yml will be kept as in Case 2.
I spent all day trying to make Zuul + Eureka work together, but I hasn't been lucky with that. Zuul alone, without Eureka, works fine. I've tried a lot of different configurations like this one, which says that all I have to do is turn Zull in an Eureka client (by using #EnableDiscoveryClient at root application class).
My setup is very simple: it consists of a service:8080 (service 1), Zuul:9000 and Eureka:8761.
All the approaches I've tried using Eureka gave me the same error when I tried to access service 1 using Zull (http://localhost:9000/service1 in this case):
com.netflix.zuul.exception.ZuulException: Forwarding error
(...)
com.netflix.client.ClientException: Load balancer does not have available server for client: service1
Service 1 is working fine (I can access it directly from the browser address bar http://localhost:8080) and Eureka shows both Zull and Service 1 correctly registered:
The apps are configured like:
Service 1 (bootstrap.yml):
spring:
application:
name: service1
Service 1 (application.yml):
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
Zuul:
ribbon:
eureka:
enabled: false
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
healthcheck:
enabled: true
server:
port: 9000
Eureka:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
logging:
level:
com:
netflix:
eureka: OFF
discovery: OFF
Zuul Annotations at root application class:
#EnableZuulProxy
#EnableDiscoveryClient
Am I missing any important point?
From the spring doc, I see we can have peer eureka server together, so for Eureka1, in application.yml, I can have:
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/
And in Eureka Server 2, I can have:
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
Now these two eureka servers are aware each other, it is good.
BUT, now in configuring client, when they register again Eureka, how to do this?
In my client application, I have:
eureka:
instance:
hostname: ${host.instance.name:localhost}
nonSecurePort: ${host.instance.port:8080}
leaseRenewalIntervalInSeconds: 5 #default is 30, recommended to keep default
metadataMap:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
serviceUrl:
defaultZone: http://(eurekaServerHost):8761/eureka/
server:
port: ${host.instance.port:8080}
So now my question is shall I use peer1 or peer2 as EurekaServerHost in the client application.yml?
Thanks
Use a comma separated list of peers in eureka.client.serviceUrl.defaultZone.
eureka.client.serviceUrl.defaultZone=http://<peer1host>:<peer1port>/eureka,http://<peer2host>:<peer2port>/eureka
We are running in a peer to peer Eureka configuration. See below for the configuration.
So when the services are started, they register to 10.202.10.95 (the primary) and we see them there with none showing on 10.202.10.97 (the secondary)
If we kill 10.202.10.95 (the primary) then we see them show up on 10.202.10.97 (the secondary eureka).
If we restart 10.202.10.95 (which was the primary), we see the services show up on 10.202.10.95 and also on 10.202.10.97. So services are visible on both eureka servers
If we restart 10.202.10.97 (the secondary), the services vanish and are just visible on the primary (10.202.10.95)
Case 3 is unexpected to me. Is this a case of improper peer to peer Eureka configuration?
The eureka configuration is as follows: (we point these 2 instances to each other in a peer to peer configuration)
spring:
profiles: api06-prod-int-discoveryserver # 10.202.10.95 eureka host
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.97:8761/eureka/
---
spring:
profiles: api05-prod-int-discoveryserver # 10.202.10.97 eureka host
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.95:8761/eureka/
Each service has its configuration to eureka set like this: (we point to both instances with x.x.x.95 being the primary)
eureka:
# these are settings for the client that gets services
client:
# enable these two settings if you want discovery to work
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://10.202.10.95:8761/eureka/,http://10.202.10.97:8761/eureka/
So, following some other posts and Spencer's response I checked and my configuration was incorrect. After I changed it, it responds correctly.
This is the Eureka settings. I run 2 eureka servers, one with profile peer1 and the other with profile peer2.
---
spring:
profiles: peer1 # not standalone
server:
port: 8761
eureka:
instance:
hostname: peer2
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://localhost:8762/eureka/
---
spring:
profiles: peer2 # not standalone
server:
port: 8762
eureka:
instance:
hostname: peer1
leaseRenewalIntervalInSeconds: 3
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
The Service that I have connecting is configured like this
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
instance:
statusPageUrlPath: /${info.app.name}/manage/info
homePageUrlPath: /${info.app.name}/manage
healthCheckUrlPath: /${info.app.name}/manage/health
preferIpAddress: true
After I run my service, I can see it connect to both discovery services and if I kill either then it is visible on the other discovery service.