问题
I am new to microservices, so while reading about it,I can't understand the below paragraph when talking about the load balancing, how the client will do something like this?
"When using client‑side discovery, the client is responsible for determining the network locations of available service instances and load balancing requests across them."
回答1:
A Microservice architecture involves a number of services that may have hierarchical dependencies. For example, Service A depends on Service B and Service B in turn depends on Service C and so on. Again, there can be multiple instances of each services and the location at which they are deployed may change dynamically. For example, Service C is getting too many hits and you may dynamically scale up/down this service.
Usually, an end user cannot access any of these micro-services directly. It can be accessed only through a edge-service whose location is fixed, say www.microservice.com/apis, and will be responsible for doing authentication, rate limiting etc. So, all service calls will go through the edge-service and load balancing at this stage is primarily achieved using a hardware load balancer OR Amazon ELBs.
Now, suppose that a user wants to access Service A. He has to go through edge-service which will delegate the request to Service A. Service A has to call Service B to get some information. In this case, Service A is a client of Service B and Service A need to find all the available instances of B and then make a call to one of these instances. This is where a Microservice Registry like Consul,Eureka etc comes into picture. Each service instance will be continuously updating its status (IP, Port, Up/Down etc) to the registry. The edge-service will also be using this registry to find the instance location of Service A.
Service A should also make sure that all calls to Service B are load balanced. It is not feasible to use ELBs for load-balancing here because it means you need to have 50 ELBs if you have 50 services. There are software load-balancers that can do this in a more effective manner. For eg: Ribbon is a good Http client library with load-balancer support written in Java.
回答2:
the client is responsible for determining the network locations of available service instances and load balancing requests across them.
I'm not sure where you are reading that, but the whole concept of a service consumer being forced to implement load balancing is ridiculous.
The client-side discovery pattern is actually just another way of saying defer call routing (and sometimes channel construction) until run-time by way of a service registry. As Richardson says in his patterns pages:
When making a request to a service, the client obtains the location of a service instance by querying a Service Registry, which knows the locations of all service instances.
Load balancing is a completely different concern, and would always be delegated, ideally to an actual load balancer, though depending on the services platform you are using you may have access to some kind of in-process distributor.
来源:https://stackoverflow.com/questions/42549749/micro-services-client-side-discovery