Issue
I have been working with spring
and now would like to learn spring boot
and microservices. I understand what microservice
is all about and how it works. While going through docs i came across many things used to develop microservices
along with spring boot
which i am very much confused.
I have listed the systems below.and the questions:
- Netflix Eureka - I understand this is service discovery platform.
All
services
will be registered toeureka
server and allmicroservices
areeureka
clients. Now my doubt is , without having an API gateway is there any use with this service registry ? This is to understand the actual use of service registry. ZUULApi gateway- I understand ZUUL can be used as API gateway which is basically a load balancer , that calls appropriate microservice corresponding to request URL. iS that assumption correct? will the api gateway interact with Eureka for getting the appropriate microservice?
NGINX - I have read
NGINX
can also be used as API gateway? Is that possible? Also i read some where else likeNGINX
can be used as a service registry , that is as an alternate for Eureka ! Thus which is right? Api gateway or service registry or both? I knownginx
is a webserver andreverse proxies
can be powerfully configured.AWS api gateway - Is this can also be used as an alternate for
ZUUL
?RIBBON - for what
ribbon
is used? I didn't understand !AWS ALB- This can also be used for load balancing. Thus do we need ZUUL if we have
AWS ALB
?
Please help
Solution
Different systems which can be used for the working of microservices
, that comes along with spring boot:
Eureka: Probably the first microservice to be UP. Eureka is a service registry, means , it knows which ever microservices are running and in which port. Eureka is deploying as a sperate application and we can use
@EnableEurekaServer
annotation along with@SpringBootAPplication
to make that app a eureka server. So our eureka service registery is UP and running. From now on all microservices will be registered in this eureka server by using@EnableDiscoveryClient
annotation along with@SpringBootAPplication
in all deployed microservices.Zuul: ZUUL is a
load balancer
,routing
application andreverse proxy
server as well. That is before we were using apache for reverse proxy things , now , for microservices we can use ZUUL. Advantage is, in ZUUL we can programatically set configurations, like if /customer/* comes go to this microservice like that. AlsoZUUL
can act as a load balancer as well , which will pick the appropriate microservice in a round robin fashion. SO how does the ZUUL knows the details of microservices, the answer is eureka. It will work along witheureka
to get microservice details. And in fact this ZUUL is also a Eureka client where we should mark using@EnableDiscoveryClient
, thats how these 2 apps(Eureka and zuul) linked.Ribbbon: Ribbon use for load balancing. This is already available inside ZUUL, in which zuul is using Ribbon for load balancing stuff. Microservices are identified by service-name in properties file. IF we run 2 instances of one microservices in different port, this will be identified by Eureka and along with Ribbon(Inside zuul), requests will be redirected in a balanced way.
Aws ALB , NGINX , AWS Api gateway etc: There are alternatives for all the above mentioned things. Aws is having own load balancer, service discovery , api gateway etc . Not only AWS all cloud platofrms ,like Azure, have these. Its depends which one to use.
Adding a general question as well , How these microservices communicate each other: Using
Resttemplate
orFeignclient
actual rest API can be called or Message queues likeRabbit MQ
etc can be used .
Answered By - vipin cp
Answer Checked By - Mary Flores (JavaFixing Volunteer)