why consumer has to register with eureka server? - microservices

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.

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.

Stop specific instance to register Eureka

I have a eureka server running on test server and multiple services registers from test server to this eureka server.
Now problem is sometimes developers also connect their local microservice instance for some service to eureka. Due to this it shows multiple instances for that service on eureka and load balancer starts sending request to local servers as well from feign client. That causes issues in testing as test server is not able to connect local developers machine in feign client calls.
I instructed developers to set eureka.client.register-with-eureka=false from local but still if someone connects how can I stop that. Is there a way that eureka server registers only from specific IP (test server ip)? Or any other solution to prevent this problem?
For the services that you don;t want them to register, remove #EnableDiscoveryClient from the services. #EnableDiscoveryClien lives in spring-cloud-commons and picks the implementation on the classpath. This will stop your services from getting discovered but then you won;t be able to make the Feign calls to other services and take the benefit of load balancing your calls.

What to put as discoverable services when using Eureka?

I am following a course about microservice architecture using spring, covering netflix's eureka.
The clientui serves webpages and calls the 3 microservices when needed.
The config-server serves configuration for the 3 microservices from a git repo.
Of course the 3 microservices are registered as eureka clients.
My questions are :
should the config server and also be registered as an eureka client, or is there no benefit in doing so?
what about the clientui (which is the web entry point) ? can it be registered as an eureka client in order to benefit from load balancing system and if yes, how then should the app be accessed by clients?
About your first question :- Yes you can register config server as eureka client. Benefit of this will be that in terms of service management it will give you a single point of visibility of all the services. Also later if you try to expand your app in terms of distributed architecture and say you implement an api gateway like zuul, it will be easy for you to setup a fallback config server say if one config server goes down requests can be routed to other config server and so on.
About your second question :- Honestly speaking , I didn't understand it very well in first place. I have never seen any ui service registering to eureka so I am not very sure about this. Still if you have more doubts about it , you can let me know like is it a angular ui or is it a http based client or what.

what is the difference between netflix zuul server and netflix eureka server?

i have created two java spring-boot micro services they are
1) producer
2) consumer
and i have used spring eureka server for service registration and discovery . it worked fine . then what is the use of Netflix Zuul.
Let's suppose you have 20 services to which user can interact to, and of course we are not going to expose each and every services publicly because that will be madness (because all services will have different ports and context), so the best approach will be to use an API gateway which will act as single entry point access to our application (developed in micro service pattern) and that is where Zuul comes into picture. Zuul act as a reverse proxy to all your micro-services running behind it and is capable of following
Authentication
Dynamic Routing
Service Migration
Load Shedding
Security
Static Response handling
Active/Active traffic management
You can go through documentation here
If you have enough experience in the domain, you could look at zuul as an API gateway like Apigee. It is very feature rich and touches up on a lot of different concerns like routing, monitoring and most importantly, security. And eureka as a service discovery platform that allows you to load balance (in Linux terms the nginx or haproxy) and fail over between your service instances.
Typically the backend services that perform the server side business operations (i.e. core) are not exposed publicly due to many reasons. They are shielded by some Gateway layer that also serves as reverse-proxy. Netflix Zuul serves as this gateway layer which easily gives you the capabilities as mentioned by #Apollo and here

If the web service A is down, how can you make the osb business service point to web service B

If the web service A is down, how can you make the osb business service point to web service B.
This is like a back up web service.
So, try invoking web service A, but if it is unavailable invoke web service B.
OSB supports multiple endpoint URLS with load balancing algorithm, and you can provide retry count there so in case if the service is not available on one endpoint then it will be tried to second endpoint.
You will need to handle it with Stage (or Route) Error Handler in the Proxy Service
If it is truly the same Business Service (same WSDL), then look at the Load Balancing Algorithm and the Endpoint URI list on the Business Service properties.

Resources