Fetch docker container name of microservices registered with the Eureka server - spring-boot

Does the Eureka server have information on container image names for registered applications? I am working on a spring-boot microservices application in which it is necessary to get image names during registration or subsequent health checks. Eureka server can provide a lot of information about the application registered (using the InstanceInfo object), but there is no information such as container/image name. Or would it be possible to query application metadata for such information? Or is there any other approach that can be use din achieving this task?

Related

What is the use of Eureka Server in Microservices architecture

I am using "Spring Cloud Gateway" in my microservices application
Ex:
spring.cloud.gateway.routes[0].id=mydemoservice
spring.cloud.gateway.routes[0].uri=http://localhost:8100/
spring.cloud.gateway.routes[0].predicates[0]=Path=/mydemoservice/**
In this case if the request is coming from client like : http://localhost:8100/mydemoservice/api/getdetails
in this case "Spring Cloud Gateway" will route the request to respective service.
But why is Eureka Server required here ? I am not really understanding Eureka Server use here can some please explain.
Best I could find is this medium article which depicts the problems and solutions Eureka provides.
https://medium.com/javarevisited/how-to-use-spring-cloud-gateway-to-dynamically-discover-microservices-194c0c3869c6
This comes to shine when you deploy services with horizontal auto scalability (such as kubernetes). At certain moments, based on the equation you configure (recourse usage, client connections, etc.) the orchestration can and will scale your services (e.g. mydemoservice). It can scale your service instance up to:
the configured max number of instances
until the service usage limit is reached
either way, all of them will have different IP addresses.
Eureka is a discovery/registry service which provides to your gateway information of which cluster/load balancer (IP address) will it pass the request based on Round Robins and such algorithms. The gateway needs to configure all of the services but it will use aliases provided by the Eureka server depicted as such:
https://github.com/rubykv/code-examples/blob/master/gateway/src/main/resources/application.yml
In this example, we see the gateways are configured for services: subject, student, and eureka.
Eureka has a dashboard:
https://miro.medium.com/max/1400/1*KgT1_hnuXvX6xldyiJJuaQ.png
and will display all eureka clients. To display a service as a eureka client one must implement:
https://github.com/rubykv/code-examples/blob/master/student/pom.xml (netflix eureka and open feign)
annotate application with #EnableFeignClients https://github.com/rubykv/code-examples/blob/master/student/src/main/java/com/example/demo/StudentApplication.java
There are lots of tutorials and articles on medium, I hope this helps for your further investigation.

Spring boot micro service Deployment

I am new to Micro services architecture.. I want know if it is required to deploy all Spring boot micro services in the same local network ..? As Eureka Discovery service uses Private/Internal IP Address for Registration , i am unable to call a services from another service deployed in different local network...
Please let me know how micro services deployed across multiple Sub nets should communicate each other in this case
or is there a way to tell eureka to use only public IP Address..?
Not sure if this would help, but by default, your eureka client will try to connect to the default localhost:8761 where the eureka discovery server should exist.
In case you have a different location for your discovery-service you can use the following in the application.properties file in your client services.
eureka.client.service-url.defaultZone=http://{address}-{port}/eureka

why consumer has to register with eureka server?

I am currenly learning microservices. I have two services Service A and Service B. Service A registered with Eureka server. Service B is calling Service B via Eureka server to get the response. My question is
why Service B has to register with Eureka service in order to call Service A?
Service B can get the Service A url and portno through service discovery from Eureka server. What is the significance of Service B to register with Eureka server?
Typically in Microservices architecture, we have a lot of small applications running independently together, and ofcourse they will all have their own URLs and ports.
In that scenario, it would be very cumbersome to maintain all these microservices to run in synchronization, and more importantly, with monitoring. This problem will increase manifold when we start implementing load balancers.
To solve this issue, we need a tool that will monitor and maintain the registry of all the microservices in the ecosystem.
That's why Eureka server acts as directory and service discovery system to make sure they is no direct binding between services and it make sure to have health check for those services.

which is the best API gateway for micro services using spring?

I am trying to build a simple application with microservices architecture.
Below are the details about 3 microservices I have created.
1] Customer.
database: mongodb
server : embeded tomcat server.
port : 8081
2] vendor.
database: mongodb
server : embeded tomcat server.
port : 8082
3] product.
database: mongodb
server : embeded tomcat server.
port : 8083
All the 3 micros runs on an embeded tomcat server.
Now I want to create a common gateway for all these micros [API gateway].
which help me to route my request based on the request I get for example:-
for example if I get a request of http://hostname:port_of_gateway/customer.
on reading this I need to route the request tom my customer micro and fetch its response and send it back to client.
Which of the spring tool I can use to achieve this?
Because your requirements are quite simple you can implement such a gateway by yourself. Here's an example.
But if you really want to use some Spring solution you can try to use Spring Cloud Netflix which is a part of Spring Cloud umbrella project. It includes router and filter features which in turn based on Netflix Zuul gateway service.
Note that this is not a complete standalone application but a library. Therefore you still should create another microservice that would act as API gateway in your application. To make it a gateway you should just add #EnableZuulProxy annotation to the same class that has #SrpingBootApplication annotation. You can find a very good example here.
Please also note that you should somehow inform the gateway about your microservices' addresses for redirection. It can be done in two general ways:
By statically defining the addresses in gateway microservice's configuration;
By applying service discovery pattern in conjunction with e.g. Netflix Eureka service registry.
The 1st approach is easy and straightforward but is not very well for large number of microservices and/or when microservices' locations can change dynamically (e.g. due to auto-scaling).
The 2nd approach requires additional component - service registry - and needs modification of other microservices (to let them register themselves in the registry). This is quite more complicated approach but is the only possible in case of complex architecture. Simple yet expressive example can be found in the same article.
UPDATE (January'19)
As of December 2018 the Spring Cloud team announced that almost all Netflix components in Spring Cloud (except Eureka) entered maintenance mode. It means that for the next year they won't receive any feature updates (only bugs and security fixes).
There are replacements for all the affected components, including Netflix Zuul aforementioned above. So please consider using Spring Cloud Gateway instead of it in new projects.

Spring cloud registering multiple instances of same service

I am developing a microservice, using Spring Boot, that exposes REST Endpoint. Because of scalability, I have to run multiple instances of this services on a different port. What will be the configurations for the applications so that it can register with eureka and requests are load balanced? I am using Spring cloud config, Eureka server and zuul.
Attaching following entries in the client properties file will do the trick. This is for Spring cloud config dalston
eureka.instance.instanceId=${spring.application.name}:${spri‌​ng.application.insta‌​nce_id:${random.valu‌​e}}
I guess you meant to register with Eureka instead of Config server.
To register multiple instances that might be running in the same host but listening on a different port you would need to set eureka.instance.metadataMap.instanceId to a unique value maybe using:
eureka.instance.metadataMap.instanceId=${spring.application.name}:${random.int}

Resources