spring cloud gateway 负载均衡流程
网关被扫描后会注册四个核心配置类,当然在配置类中仍然有各种流程中需要的bean后面会详细解释。
l GatewayAutoConfiguration 网关基础配置类,当中承载着核心的配置逻辑
l GatewayClassPathWarningAutoConfiguration 网关类加载配置类,就是用于校验是否加载的时webFlux依赖,而不是普通的web依赖。
l GatewayLoadBalancerClientAutoConfiguration 网关客户端负载均衡配置类
l GatewayRedisAutoConfiguration 网关限流器配置类
我们先回过头,假如你已经搭建了一个gateway的demo,那么在网关中进行负载均衡,会添加注解如下:
@RibbonClient(name = "pay-server", configuration = {IRule2.class})
@Configuration @ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class, DispatcherHandler.class}) @AutoConfigureAfter(RibbonAutoConfiguration.class) public class GatewayLoadBalancerClientAutoConfiguration { // GlobalFilter beans @Bean @ConditionalOnBean(LoadBalancerClient.class) public LoadBalancerClientFilter loadBalancerClientFilter(LoadBalancerClient client) { return new LoadBalancerClientFilter(client); } }
RibbonClientConfigurationRegistrar
private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name, Object configuration) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(RibbonClientSpecification.class); builder.addConstructorArgValue(name); builder.addConstructorArgValue(configuration); registry.registerBeanDefinition(name + ".RibbonClientSpecification", builder.getBeanDefinition()); }
相关推荐
tinydu 2020-08-09
azhuye 2020-11-12
liupengqwert 2020-10-28
YzhilongY 2020-08-31
crazyjingling 2020-08-16
swtIrene 2020-08-14
slovyz 2020-08-14
tinydu 2020-08-03
Studynutlee 2020-08-03
快乐de馒头 2020-07-29
yungame 2020-07-27
buaichidoufu 2020-07-28
wanjichun 2020-07-26
极地雪狼 2020-07-26
yungame 2020-07-04
畅聊架构 2020-06-28
极地雪狼 2020-06-27
廖先贵 2020-06-23