com.nepxion.discovery.plugin.framework.configuration.NacosLoadBalanceConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-framework-nacos Show documentation
Show all versions of discovery-plugin-framework-nacos Show documentation
Nepxion Discovery is an enhancement for Spring Cloud Discovery
package com.nepxion.discovery.plugin.framework.configuration;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfiguration;
import com.nepxion.discovery.plugin.framework.decorator.NacosServerListDecorator;
import com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ServerList;
@Configuration
@AutoConfigureAfter(NacosRibbonClientConfiguration.class)
public class NacosLoadBalanceConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@Autowired
private LoadBalanceListenerExecutor loadBalanceListenerExecutor;
@Bean
public ServerList> ribbonServerList(IClientConfig config, NacosDiscoveryProperties nacosDiscoveryProperties) {
NacosServerListDecorator serverList = new NacosServerListDecorator(nacosDiscoveryProperties);
serverList.initWithNiwsConfig(config);
serverList.setEnvironment(environment);
serverList.setLoadBalanceListenerExecutor(loadBalanceListenerExecutor);
return serverList;
}
}