Spring cloud - Server and client - spring-cloud

I'm config an application using spring cloud eureka. I start my discovery app in the 8761 port and reaching the console in "http://localhost:8761".
So, I start my client application and it's appear in the "Application" page of eureka console.
First question:
My client is using "server.port=0" in properties config so the tomcat port is starting in random. How can I reaching my services in client? Example: I have a get request in "/api/stuff", is that possible to access this not using the random port? Suppose I don't know the port!
Second Question:
I can start any clients I want, they will start, assuming a random port and register in the cloud server discovery, I can see the log:
"Registering application FLY-CLIENT with eureka with status UP"
But they don't appear in "Application" page of eureka console, why they don't appear?
Thanks!

If you are using Spring RestTemplate to request the services registered in Eureka you need to make it #LoadBalanced, something like this should do the try:
#LoadBalanced
#Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
// usage
restTemplate.getForObject("http://your-service-name/api/stuff", StuffResponse.class);
As for the 2nd question, I'm a little confused, as you mentioned earlier in the question that your application appears on Eureka's dashboard. Is this behavior only happening for the "fly-client"?

Related

Get Eureka instance metadata in browser

I have a Spring Boot (2.4) app (a generic service) and a Eureka discovery server running. The server doesn't register itself as an instance. I am able to navigate to the Eureka dashboard at the default location of localhost:8761 to get an overview of all the registered instances. I successfully see the service is registered in Eureka. However, this dashboard doesn't give any details about the instance except the name and the port number. I want to be able to see the instance meta data. Is this possible using the dashboard? O maybe there is some exposed URL by the Eureka server that I can call in a browser or postman? Or is there an URL available in the Eureka client (the service) that gives details about its Eureka metadata?
I read thet feign clients access something to be able to query the registry. Can I mimic this as human in a browser?
Go to localhost:8761/eureka/apps

Spring boot admin behind firewall

I have a spring-boot client app deployed in a customer network and I want to use SBA as a GUI for its actuator endpoints. I cannot use register-client-applications to register the app, mainly because the client app has no connectivity to SBA (its behind a firewall).
Is there a way how to add a client to SBA manually?
You can add use a static configuration for spring cloud's discovery client. So there is no need that the client reach the sba server. See http://codecentric.github.io/spring-boot-admin/current/#spring-cloud-discovery-static-config

Ribbon- Calling a specific uri of an application from urls obtained from Eureka

Lets consider the following situation.This example will only have urls containing localhost. I have a zuul proxy setup and lets say its running on port 8080. So
Zuul proxy-
localhost:8080
I have an eureka server setup running on port 81.
Eureka server-
localhost:8081.
I have an application lets call it by name-example which is a REST web service. Its running on 3 different ports 82,83 and 84. All 3 instances are registered with eureka server. I have a filter setup in zuul for the uri /example.
So i expect consumers to call the zuul proxy at locahost:8080/example.
Now, in the application example for the request mapping /example, there is a controller setup.
So what i want to do is basically have the consumers call localhost:8080/example and route that request to localhost:8082/example, localhost:8083/example, localhost:8084/example . I know how to load balance using ribbon and eureka and have all the appropriate properties set to achieve that.
zuul.routes.example.serviceid=example
ribbon.eureka.enabled=true.
What i want to do is have ribbon look up the list of url(s) from eureka server and then call localhost:8082/example rather localhost:8082.
Is this possible?
Thank you in advance.
You need to specify the path & serviceId
zuul:
routes:
examplepath:
path: /example/**
serviceId: name-example
stripPrefix: false
The serviceId is the name registered with Eureka. Hope you are specifying Eureka server details in you Zuul gateway.

How can I get specific diagnostic information on an IP address from Zuul?

I have Zuul and Eureka running, with a bunch of smaller services. Using Eureka, I can see all of the services and their associated host/IP address. Usually, I can boot up multiple instances of another service and Eureka will pick them up for Zuul to route to. I'm currently having an issue where I have three instances of a service registered in Eureka, but Zuul only routes to one of them. I don't know where to go to get diagnostic information from Zuul to understand why it isn't routing to the other two instances. I've tried simple things, like manually sending requests from the Zuul box to the service boxes to make sure they can communicate.
Does Zuul expose an endpoint to list hosts/IP addresses and their status? What are my diagnostic options?
You can try to list all your endpoints with the routes endpoint
So, if you running zuul on your localhost on port 8080 you can do a GET call to http://localhost:8080/routes and you will get something like
{
/stores/**: "http://localhost:8081"
}
Depending on the version you are using, you also need to set
management.security.enabled = false
in the application.properties
EDIT:
You can also use the logging mechanism.
Set the loglevel just of the LoadBalancerContext to debug in application.properties
#logging
logging.level.com.netflix.loadbalancer.LoadBalancerContext=DEBUG
It will log each call that is routed.

When closing a Eureka Clients, the RestTemplate with #LoadBalanced will continue call the closing service, how fixed it?

I use Eureka and Spring Cloud;
Start 2 Eureka Clients;
When closing a Eureka Clients, the Eureka client unregister from Eureka server need a little time (3-5 minutes);
the RestTemplate with #LoadBalanced will continue call the closing service, how fixed it?
I believe a Eureka client app doesn't go through the Eureka server to get metadata about another Eureka client app for every request. This means a Eureka client app keeps a cache of the registry, if another Eureka client app deregisters, its metadata might still be caches in the previous client until it syncs with the Eureka server.
This behavior might be configurable through one or a combination these settings:
eureka:
instance:
registryFetchIntervalSeconds:
leaseRenewalIntervalInSeconds:
leaseExpirationDurationInSeconds: