Eureka Client: Eureka Registry server address alternative to 'localhost' - spring-boot

Eureka-server(MediaStoreEurekaServer): bootstrap.properties
spring.application.name=MediaStoreEurekaServer
server.port=9091
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Eureka-client(Config-Server): bootstrap.properties
spring.application.name=Config-Server
server.port=9093
user.home=${HOME}
spring.cloud.config.server.native.search-locations=file://${user.home}/IdeaProjects/MediaStore/centralProperties
spring.profiles.active=native
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka
With above 2 properties (services running on same machine), Config-Server is able to register with MediaStoreEurekaServer eureka registry server when using http://localhost:9091/eureka.
I don't want to use localhost. When I use http://MediaStoreEurekaServer:9091/eureka , Config-Server is not able to register.
Can we use something other than localhost for eureka client to find the eureka server like service or instance name? when services are running on same host
Edit 1:
This is what eureka client spring logs give when in eureka client properties file i set
eureka.client.serviceUrl.defaultZone=http://MediaStoreEurekaServer:9091/eureka
Error:
2020-05-22 20:01:02.137 ERROR 22846 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://MediaStoreEurekaServer:9091/eureka/}
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: MediaStoreEurekaServer```

Related

Eureka client registration with external git repo configuration files

I have an external configuration repository on git containing all my propertie files.
My eureka client is microservice-order with this application file :
spring.application.name=microservice-order
spring.config.import=configserver:http://localhost:9101
This application file point to "microservice-order" propertie files :
server.port=9001
spring.data.mongodb.uri=mongodb+srv://admin:************#cluster0.yqhwqrj.mongodb.net/Facebouffe?retryWrites=true&w=majority
#configurations
configs.setOrderLimit= 5
#eureka
spring.application.name = microservice-order
eureka.client.serviceUrl.defaultZone: http://localhost:9102/eureka/
My eureka server has this propertie file :
spring.application.name=eureka-server spring.config.import=configserver:http://localhost:9101
pointing to exteral repo file "eureka-server.properties":
`
server.port= 9102
eureka.client.serviceUrl.defaultZone = http://localhost:9102/eureka/
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
spring.cloud.config.import-check.enabled=false`
I wrote "#EnableEurekaServer" (eureka-service-discovery) for server class and "#EnableEurekaClient" for client class (microservice-order)
When i start configserver, its running on 9101 port
When i start eureka-service-discovery, its running on 9102 port
When i start microservice-order, its running on 9001 port
So, each class load its own propertie files, but when i connect to http://localhost:9102/ , there is no service registered.
Do you have any idea ?
thank you !
I'm trying to register an eureka client to eureka server with external propertie files repository on github.

Spring cloud client trying to run on server port 8888

The config server is up and the client is able to fetch the properties from config server.
HTTP GET http://localhost:8888/account-service/dev/config
Accept=[application/json, application/*+json]
Response 200 OK
But the problem is, client service is trying to start on config server port 8888. I have set server.port=8080 in the client but still not working.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8888 was already in use.
Am I missing any configuration here? Highly appreciate any help.
Config server application.properties,
spring.application.name=config-server
spring.cloud.config.profiles=dev
spring.cloud.config.server.git.uri=REPO_URL
server.port=8888
Finally, I was able to find the solution. When I was trying to start client service, server.port was also getting overridden with config server port. I added server.port=8080 in the properties file for the client service profile in config repo (account-service.properties) and it worked.

Health check properties for springboot application in PCF

I have configured the below health check properties in my spring boot application(using actuator) and returning "UP" when locally tested using the below endpoint
server:
servlet:
context-path: /account/v1
port: 8443
management:
endpoints:
web:
path-mapping:
health: /health
Check locally using "http://localhost:8443/account/v1/actuator/health and returning
{"status":"UP"}"
In PCF I updated the Health check type as "http" and Endpoint as "/actuator/health".
When I pushed my app I am getting the below error
2020-09-02T12:43:15.92+0530 [HEALTH/0] ERR Failed to make HTTP request to '/actuator/health' on port 8080: connection refused
2020-09-02T12:43:15.92+0530 [CELL/0] ERR Failed after 1m0.632s: readiness health check never passed.
Please help on this.(Is my port or endpoint wrong)

Is Eureka running on 8761 or 8080?

I've created a new spring boot project with "spring-cloud-starter-netflix-eureka-server" dependency. Also have added "#EnableEurekaServer" annotation and launched the spring boot app.
I see the below log messages
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
c.n.eureka.cluster.PeerEurekaNodes : Adding new peer nodes [http://localhost:8761/eureka/]
From above, as I understand. Tomcat is running on port 8080 and eureka server is running on port 8761.
If so,
How come the Eureka Dash board is accessible at http://localhost:8080/ ? When the eureka server is running on port 8761 ?
On one of the client, I configured the following in the .properties file
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
Above, I specified the Eureka server location. But, why is the client unable to register?
Thanks!
By default it works on 8761, so configure server.port=8761

Zuul Forwarding error - Trying to connect to a different(unknown) ip

I have configured zuul proxy and eureka naming server for my spring boot application. Zuul proxy run on port 8765 and eureka runs on port 8761.
Also two other microservices, user-service and message-service run on port 8081 and 8082.
Also I have used swagger for the zuul proxy service where i can find all microservices api in one place.
Swagger configuration in Zuul proxy service
#Component
#Primary
#EnableAutoConfiguration
public class Controller implements SwaggerResourcesProvider{
#Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources= new ArrayList<>();
SwaggerResource user = new SwaggerResource();
user.setName("USER-SERVICE");
user.setLocation("/api/user/v2/api-docs");
user.setSwaggerVersion("2.0");
resources.add(user);
SwaggerResource message = new SwaggerResource();
message.setName("MESSAGE-SERVICE");
message.setLocation("/api/message/v2/api-docs");
message.setSwaggerVersion("2.0");
resources.add(message);
return resources;
}
}
application.yml of Zuul proxy
server:
port: 8765
eureka:
client:
serviceUrl:
defaultZone: http://eureka-naming-server:8761/eureka/
instance:
prefer-ip-address: true
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
zuul:
prefix: /api
sensitive-headers: Cookie,Set-Cookie
routes:
user-service:
path: /user/**
service-id: USER-SERVICE
message-service:
path: /message/**
service-id: MESSAGE-SERVICE
Also i have used docker-compose file to up the docker microservices with default subnet (169.254.3.0/24).
ip address of user-service is 169.254.3.6
ip address of message-service is 169.254.3.10
Here is the issue
When I call these services via zuul proxy swgger ui, often i am getting 500 error. That for the first time i hit the specific url it throws 500 error.
but after few attempt i get the response.
Zuul log which indicate problem
com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out
I have no idea about 172.22.97.14:8081, why is not try to connect 172.22.97.14:8081 instead of connect to 169.254.3.6:8081
Can someone help me to understand what is happening in here..
Any help would be grateful !
[Edit]
zuul proxy container ip is 169.254.3.10
This problem occured on my project when I was using the same Zuulserver for developing microservices on localhost and DEV environment (when I started microservis on localhost it connected to zullserver on DEV env.). Then when I tried to call some operation through zuulserver it tried to connect to microservis not on DEV env. but on my machine.
I suspect the same problem on your side and IP on which you are developing your application is 172.22.97.14:8081.

Resources