Ribbon: client load balancing

I. Introduction

1. Address List provider configuration services for the Ribbon, Ribbon will be some sort of load balancing algorithm to automatically help consumers to service requests;

Ribbon 2. When used in conjunction with the Eureka, Eureka Ribbon punch Server automatically acquired service provider address list, and examples based on load-balancing algorithm, wherein a request for a service provider;

3. Consumer Services Integration Ribbon

Add spring-cloud-starter-netflix-ribbon-dependent;

RestTemplate increase @LoadBalanced to comment;

Controller address in the request to change the name of the virtual host micro services;

4.Ribbon Configuration

@RibbonClient annotations configuration properties, you can customize the Ribbon configured to specify the name of the client;

To customize a Ribbon Configuring a client, the packet must be prevented @Configuration annotation class is scanned with @ComponentScan packet overlap, or not to be displayed specified @ComponentScan @Configuration scan package where the class;

Use custom attributes:

  NFLoadBalancerClassName: Configure ILoadBalancer implementation class;

  NFLoadBalancerRuleClassName: Configure IRule implementation class;

  NFLoadBalancerPingClassName: Configure IPing implementation class;

  NIWSServerListClassName: ServerList implementation class configuration;

  NIWSServerListFilterClassName: Configure ServerListFilter implementation class;

5. departing from the Ribbon Eureka

If you want to use the Ribbon alone, without using the Eureka service discovery function, you need to add configuration ribbon.eureka.enabled = false;

If you only want to specify the name of the Ribbon Client using the specified URL request, other Ribbon Client is still used in conjunction with Eureka, you can configure

  <clientName>.ribbon.NIWSServerListClassName = com.netflix.loadbalancer.ConfigurationBasedServerList

  <clientName>.ribbon.listOfServers = localhost:8000, localhost:8001

6. hunger load

Spring Cloud aftertaste each maintain a sub Ribbon Client application context, the default lazy loading, so the first request tend to be slower, it may be implemented in the context of the corresponding load at startup by ribbon.eager-load.enabled = true, increase first requested access speed;

Guess you like

Origin www.cnblogs.com/bbbbs/p/12562426.html