首页 > 其他分享 >nacos——01

nacos——01

时间:2022-10-26 17:07:43浏览次数:38  
标签:01 return String nacos instance nacosDiscoveryProperties registration public


nacos starter

pom依赖

<!-- nacos starter -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.0.4.0-SNAPSHOT</version>
</dependency>

spring.factories

nacos——01_注册中心


nacos——01_spring_02

这里主要看  ​​NacosServiceRegistryAutoConfiguration、NacosDiscoveryClientConfiguration、LoadBalancerNacosAutoConfiguration​

​NacosServiceRegistryAutoConfiguration​

Spring Cloud Commons 中通过三个接口,定义了实现注册中心的一套规范,这三接口在 org.springframework.cloud.client.serviceregistry 下

  • AutoServiceRegistration 负责服务自动注册
  • Registration 用于存储服务信息,规范注册到注册中心的信息
  • ServiceRegistry 定义服务注册接口,用来向注册中心注册服务

nacos分别有对应的具体实现类,就是 NacosServiceRegistryAutoConfiguration 中 @Bean 注解的那三个类


package com.alibaba.cloud.nacos.registry;
/**
* Spring Cloud Commons 中通过三个接口,定义了实现注册中心的一套规范
* org.springframework.cloud.client.serviceregistry
* AutoServiceRegistration 服务自动注册
* Registration 存储服务信息,规范注册到注册中心的信息
* ServiceRegistry 服务注册接口,用来向注册中心注册服务
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnNacosDiscoveryEnabled
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class,
AutoServiceRegistrationAutoConfiguration.class,
NacosDiscoveryAutoConfiguration.class })
public class NacosServiceRegistryAutoConfiguration {
/**
* 向注册中心注册服务
*/
@Bean
public NacosServiceRegistry nacosServiceRegistry(
NacosServiceManager nacosServiceManager,
NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosServiceRegistry(nacosServiceManager, nacosDiscoveryProperties);
}

/**
* 规范注册到注册中心的信息
*/
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration(
ObjectProvider<List<NacosRegistrationCustomizer>> registrationCustomizers,
NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) {
return new NacosRegistration(registrationCustomizers.getIfAvailable(),
nacosDiscoveryProperties, context);
}

/**
* 服务启动后自动注册到注册中心
* 继承 AbstractAutoServiceRegistration,
*
*
*/
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration);
}

}


​NacosAutoServiceRegistration​

nacos——01_spring_03


package com.alibaba.cloud.nacos.registry;
/**
* 服务启动后自动注册到注册中心
*/
public class NacosAutoServiceRegistration
extends AbstractAutoServiceRegistration<Registration> {

private static final Logger log = LoggerFactory
.getLogger(NacosAutoServiceRegistration.class);

private NacosRegistration registration;

public NacosAutoServiceRegistration(ServiceRegistry<Registration> serviceRegistry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
super(serviceRegistry, autoServiceRegistrationProperties);
this.registration = registration;
}

@Override
protected NacosRegistration getRegistration() {
if (this.registration.getPort() < 0 && this.getPort().get() > 0) {
this.registration.setPort(this.getPort().get());
}
Assert.isTrue(this.registration.getPort() > 0, "service.port has not been set");
return this.registration;
}

@Override
protected NacosRegistration getManagementRegistration() {
return null;
}
/**
* 注册,最终调用父类中注册方法
*/
@Override
protected void register() {
if (!this.registration.getNacosDiscoveryProperties().isRegisterEnabled()) {
log.debug("Registration disabled.");
return;
}
if (this.registration.getPort() < 0) {
this.registration.setPort(getPort().get());
}
super.register();
}

/**
*
*/
@Override
protected void registerManagement() {
if (!this.registration.getNacosDiscoveryProperties().isRegisterEnabled()) {
return;
}
super.registerManagement();

}

@Override
protected Object getConfiguration() {
return this.registration.getNacosDiscoveryProperties();
}

@Override
protected boolean isEnabled() {
return this.registration.getNacosDiscoveryProperties().isRegisterEnabled();
}

@Override
@SuppressWarnings("deprecation")
protected String getAppName() {
String appName = registration.getNacosDiscoveryProperties().getService();
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
}

@EventListener
public void onNacosDiscoveryInfoChangedEvent(NacosDiscoveryInfoChangedEvent event) {
restart();
}

private void restart() {
this.stop();
this.start();
}

}

具体自动注册流程如下

nacos——01_spring_04


​NacosRegistration​

nacos——01_配置中心_05

package com.alibaba.cloud.nacos.registry;

/**
* Registration 是一个空接口没有任何方法
* ServiceInstance 中定义了服务实例的各种方法
* 主要是通过 @PostConstruct 注解的 init 方法,初始化后调用
*/
public class NacosRegistration implements Registration, ServiceInstance {

/**
* The metadata key of management port.
*/
public static final String MANAGEMENT_PORT = "management.port";

/**
* The metadata key of management context-path.
*/
public static final String MANAGEMENT_CONTEXT_PATH = "management.context-path";

/**
* The metadata key of management address.
*/
public static final String MANAGEMENT_ADDRESS = "management.address";

/**
* The metadata key of management endpoints web base path.
*/
public static final String MANAGEMENT_ENDPOINT_BASE_PATH = "management.endpoints.web.base-path";

private List<NacosRegistrationCustomizer> registrationCustomizers;

private NacosDiscoveryProperties nacosDiscoveryProperties;

private ApplicationContext context;

public NacosRegistration(List<NacosRegistrationCustomizer> registrationCustomizers,
NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) {
this.registrationCustomizers = registrationCustomizers;
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
this.context = context;
}

@PostConstruct
public void init() {

Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
Environment env = context.getEnvironment();

String endpointBasePath = env.getProperty(MANAGEMENT_ENDPOINT_BASE_PATH);
if (StringUtils.hasLength(endpointBasePath)) {
metadata.put(MANAGEMENT_ENDPOINT_BASE_PATH, endpointBasePath);
}

Integer managementPort = ManagementServerPortUtils.getPort(context);
if (null != managementPort) {
metadata.put(MANAGEMENT_PORT, managementPort.toString());
String contextPath = env
.getProperty("management.server.servlet.context-path");
String address = env.getProperty("management.server.address");
if (StringUtils.hasLength(contextPath)) {
metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath);
}
if (StringUtils.hasLength(address)) {
metadata.put(MANAGEMENT_ADDRESS, address);
}
}

if (null != nacosDiscoveryProperties.getHeartBeatInterval()) {
metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL,
nacosDiscoveryProperties.getHeartBeatInterval().toString());
}
if (null != nacosDiscoveryProperties.getHeartBeatTimeout()) {
metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT,
nacosDiscoveryProperties.getHeartBeatTimeout().toString());
}
if (null != nacosDiscoveryProperties.getIpDeleteTimeout()) {
metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT,
nacosDiscoveryProperties.getIpDeleteTimeout().toString());
}
customize(registrationCustomizers);
}
/**
* 这里可以实现 NacosRegistrationCustomizer 来实现定制化
*/
protected void customize(
List<NacosRegistrationCustomizer> registrationCustomizers) {
if (registrationCustomizers != null) {
for (NacosRegistrationCustomizer customizer : registrationCustomizers) {
customizer.customize(this);
}
}
}

@Override
public String getServiceId() {
return nacosDiscoveryProperties.getService();
}

@Override
public String getHost() {
return nacosDiscoveryProperties.getIp();
}

@Override
public int getPort() {
return nacosDiscoveryProperties.getPort();
}

public void setPort(int port) {
this.nacosDiscoveryProperties.setPort(port);
}

@Override
public boolean isSecure() {
return nacosDiscoveryProperties.isSecure();
}

@Override
public URI getUri() {
return DefaultServiceInstance.getUri(this);
}

@Override
public Map<String, String> getMetadata() {
return nacosDiscoveryProperties.getMetadata();
}

public boolean isRegisterEnabled() {
return nacosDiscoveryProperties.isRegisterEnabled();
}

public String getCluster() {
return nacosDiscoveryProperties.getClusterName();
}

public float getRegisterWeight() {
return nacosDiscoveryProperties.getWeight();
}

public NacosDiscoveryProperties getNacosDiscoveryProperties() {
return nacosDiscoveryProperties;
}

@Override
public String toString() {
return "NacosRegistration{" + "nacosDiscoveryProperties="
+ nacosDiscoveryProperties + '}';
}

}


​NacosServiceRegistry​

nacos——01_spring_06

package com.alibaba.cloud.nacos.registry;

/**
* 向注册中心注册/反注册服务,设置/获取服务状态,关闭服务
* ServiceRegistry 中定义了注册、注销、关闭、设置服务状态、获取服务状态
*/
public class NacosServiceRegistry implements ServiceRegistry<Registration> {

private static final String STATUS_UP = "UP";

private static final String STATUS_DOWN = "DOWN";

private static final Logger log = LoggerFactory.getLogger(NacosServiceRegistry.class);

private final NacosDiscoveryProperties nacosDiscoveryProperties;

private final NacosServiceManager nacosServiceManager;

public NacosServiceRegistry(NacosServiceManager nacosServiceManager,
NacosDiscoveryProperties nacosDiscoveryProperties) {
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
this.nacosServiceManager = nacosServiceManager;
}

@Override
public void register(Registration registration) {

if (StringUtils.isEmpty(registration.getServiceId())) {
log.warn("No service to register for nacos client...");
return;
}

NamingService namingService = namingService();
String serviceId = registration.getServiceId();
String group = nacosDiscoveryProperties.getGroup();

Instance instance = getNacosInstanceFromRegistration(registration);

try {
namingService.registerInstance(serviceId, group, instance);
log.info("nacos registry, {} {} {}:{} register finished", group, serviceId,
instance.getIp(), instance.getPort());
}
catch (Exception e) {
if (nacosDiscoveryProperties.isFailFast()) {
log.error("nacos registry, {} register failed...{},", serviceId,
registration.toString(), e);
rethrowRuntimeException(e);
}
else {
log.warn("Failfast is false. {} register failed...{},", serviceId,
registration.toString(), e);
}
}
}

@Override
public void deregister(Registration registration) {

log.info("De-registering from Nacos Server now...");

if (StringUtils.isEmpty(registration.getServiceId())) {
log.warn("No dom to de-register for nacos client...");
return;
}

NamingService namingService = namingService();
String serviceId = registration.getServiceId();
String group = nacosDiscoveryProperties.getGroup();

try {
namingService.deregisterInstance(serviceId, group, registration.getHost(),
registration.getPort(), nacosDiscoveryProperties.getClusterName());
}
catch (Exception e) {
log.error("ERR_NACOS_DEREGISTER, de-register failed...{},",
registration.toString(), e);
}

log.info("De-registration finished.");
}

@Override
public void close() {
try {
nacosServiceManager.nacosServiceShutDown();
}
catch (NacosException e) {
log.error("Nacos namingService shutDown failed", e);
}
}

@Override
public void setStatus(Registration registration, String status) {

if (!STATUS_UP.equalsIgnoreCase(status)
&& !STATUS_DOWN.equalsIgnoreCase(status)) {
log.warn("can't support status {},please choose UP or DOWN", status);
return;
}

String serviceId = registration.getServiceId();

Instance instance = getNacosInstanceFromRegistration(registration);

if (STATUS_DOWN.equalsIgnoreCase(status)) {
instance.setEnabled(false);
}
else {
instance.setEnabled(true);
}

try {
Properties nacosProperties = nacosDiscoveryProperties.getNacosProperties();
nacosServiceManager.getNamingMaintainService(nacosProperties).updateInstance(
serviceId, nacosDiscoveryProperties.getGroup(), instance);
}
catch (Exception e) {
throw new RuntimeException("update nacos instance status fail", e);
}

}

@Override
public Object getStatus(Registration registration) {

String serviceName = registration.getServiceId();
String group = nacosDiscoveryProperties.getGroup();
try {
List<Instance> instances = namingService().getAllInstances(serviceName,
group);
for (Instance instance : instances) {
if (instance.getIp().equalsIgnoreCase(nacosDiscoveryProperties.getIp())
&& instance.getPort() == nacosDiscoveryProperties.getPort()) {
return instance.isEnabled() ? "UP" : "DOWN";
}
}
}
catch (Exception e) {
log.error("get all instance of {} error,", serviceName, e);
}
return null;
}

private Instance getNacosInstanceFromRegistration(Registration registration) {
Instance instance = new Instance();
instance.setIp(registration.getHost());
instance.setPort(registration.getPort());
instance.setWeight(nacosDiscoveryProperties.getWeight());
instance.setClusterName(nacosDiscoveryProperties.getClusterName());
instance.setEnabled(nacosDiscoveryProperties.isInstanceEnabled());
instance.setMetadata(registration.getMetadata());
instance.setEphemeral(nacosDiscoveryProperties.isEphemeral());
return instance;
}

private NamingService namingService() {
return nacosServiceManager.getNamingService();
}

}

客户端服务发现流程

nacos——01_注册中心_07

​NacosDiscoveryClientConfiguration​

package com.alibaba.cloud.nacos.discovery;

/**
* 注意这里 DiscoveryClient 的子类 NacosDiscoveryClient,用于服务发现
* 依赖入参为 NacosServiceDiscovery
* @author xiaojing
* @author echooymxq
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
@ConditionalOnNacosDiscoveryEnabled
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class,
CommonsClientAutoConfiguration.class })
@AutoConfigureAfter(NacosDiscoveryAutoConfiguration.class)
public class NacosDiscoveryClientConfiguration {

@Bean
public DiscoveryClient nacosDiscoveryClient(
NacosServiceDiscovery nacosServiceDiscovery) {
return new NacosDiscoveryClient(nacosServiceDiscovery);
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager,
NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties);
}

}


​NacosServiceDiscovery​

package com.alibaba.cloud.nacos.discovery;
/**
* 两个重要方法 getServices、getInstances
* 前者从nacos获取服务,后者获取服务下实例集合
**/
public class NacosServiceDiscovery {

private NacosDiscoveryProperties discoveryProperties;

private NacosServiceManager nacosServiceManager;

public NacosServiceDiscovery(NacosDiscoveryProperties discoveryProperties,
NacosServiceManager nacosServiceManager) {
this.discoveryProperties = discoveryProperties;
this.nacosServiceManager = nacosServiceManager;
}

/**
* Return all instances for the given service.
* @param serviceId id of service
* @return list of instances
* @throws NacosException nacosException
*/
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
String group = discoveryProperties.getGroup();
List<Instance> instances = namingService().selectInstances(serviceId, group,
true);
return hostToServiceInstanceList(instances, serviceId);
}

/**
* Return the names of all services.
* @return list of service names
* @throws NacosException nacosException
*/
public List<String> getServices() throws NacosException {
String group = discoveryProperties.getGroup();
ListView<String> services = namingService().getServicesOfServer(1,
Integer.MAX_VALUE, group);
return services.getData();
}

public static List<ServiceInstance> hostToServiceInstanceList(
List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<>(instances.size());
for (Instance instance : instances) {
ServiceInstance serviceInstance = hostToServiceInstance(instance, serviceId);
if (serviceInstance != null) {
result.add(serviceInstance);
}
}
return result;
}

public static ServiceInstance hostToServiceInstance(Instance instance,
String serviceId) {
if (instance == null || !instance.isEnabled() || !instance.isHealthy()) {
return null;
}
NacosServiceInstance nacosServiceInstance = new NacosServiceInstance();
nacosServiceInstance.setHost(instance.getIp());
nacosServiceInstance.setPort(instance.getPort());
nacosServiceInstance.setServiceId(serviceId);
nacosServiceInstance.setInstanceId(instance.getInstanceId());

Map<String, String> metadata = new HashMap<>();
metadata.put("nacos.instanceId", instance.getInstanceId());
metadata.put("nacos.weight", instance.getWeight() + "");
metadata.put("nacos.healthy", instance.isHealthy() + "");
metadata.put("nacos.cluster", instance.getClusterName() + "");
if (instance.getMetadata() != null) {
metadata.putAll(instance.getMetadata());
}
metadata.put("nacos.ephemeral", String.valueOf(instance.isEphemeral()));
nacosServiceInstance.setMetadata(metadata);

if (metadata.containsKey("secure")) {
boolean secure = Boolean.parseBoolean(metadata.get("secure"));
nacosServiceInstance.setSecure(secure);
}
return nacosServiceInstance;
}

private NamingService namingService() {
return nacosServiceManager.getNamingService();
}

}

​NacosDiscoveryClient​

package com.alibaba.cloud.nacos.discovery;
/**
* 实现 org.springframework.cloud.client.discovery.DiscoveryClient,客户端获取服务及对应实例
* 主要这俩方法:getServices/getInstances ,内部均是调用上面 NacosServiceDiscovery 的对应方法
*/
public class NacosDiscoveryClient implements DiscoveryClient {
/**
* Nacos Discovery Client Description.
*/
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";

private NacosServiceDiscovery serviceDiscovery;

@Value("${spring.cloud.nacos.discovery.failure-tolerance-enabled:false}")
private boolean failureToleranceEnabled;

public NacosDiscoveryClient(NacosServiceDiscovery nacosServiceDiscovery) {
this.serviceDiscovery = nacosServiceDiscovery;
}

@Override
public String description() {
return DESCRIPTION;
}

@Override
public List<ServiceInstance> getInstances(String serviceId) {
try {
return Optional.of(serviceDiscovery.getInstances(serviceId))
.map(instances -> {
ServiceCache.setInstances(serviceId, instances);
return instances;
}).get();
}
catch (Exception e) {
if (failureToleranceEnabled) {
return ServiceCache.getInstances(serviceId);
}
throw new RuntimeException(
"Can not get hosts from nacos server. serviceId: " + serviceId, e);
}
}

@Override
public List<String> getServices() {
try {
return Optional.of(serviceDiscovery.getServices()).map(services -> {
ServiceCache.setServiceIds(services);
return services;
}).get();
}
catch (Exception e) {
log.error("get service name from nacos server failed.", e);
return failureToleranceEnabled ? ServiceCache.getServiceIds()
: Collections.emptyList();
}
}

}


​LoadBalancerNacosAutoConfiguration​

package com.alibaba.cloud.nacos.loadbalancer;
/**
* 关键类是 NacosLoadBalancerClientConfiguration
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} that sets up LoadBalancer for Nacos.
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnLoadBalancerNacos
@ConditionalOnNacosDiscoveryEnabled
@LoadBalancerClients(defaultConfiguration = NacosLoadBalancerClientConfiguration.class)
public class LoadBalancerNacosAutoConfiguration {

}


​NacosLoadBalancerClientConfiguration​

package com.alibaba.cloud.nacos.loadbalancer;
/**
* NacosLoadBalancer nacos负载均衡核心注解,被其修饰的 RestTempate 才会有负载均衡功能
* 有两组配置:reactor及blocking,前者order优先级更高
* ServiceInstanceListSupplier 提供符合条件的实例列表,类似工厂类,这里通过
* ServiceInstanceListSupplierBuilder 这个final类的方法进行build,生成两组
*
* DiscoveryClientServiceInstanceListSupplier 基于客户端发现
* ZonePreferenceServiceInstanceListSupplier 按区域筛选委托检索的实例
* {@link ServiceInstanceListSupplier} don't use cache.<br>
* <br>
* 1. LoadBalancerCache causes information such as the weight of the service instance to
* be changed without immediate effect.<br>
* 2. Nacos itself supports caching.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
public class NacosLoadBalancerClientConfiguration {

private static final int REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER = 183827465;

@Bean
@ConditionalOnMissingBean
public ReactorLoadBalancer<ServiceInstance> nacosLoadBalancer(Environment environment,
LoadBalancerClientFactory loadBalancerClientFactory,
NacosDiscoveryProperties nacosDiscoveryProperties) {
String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
return new NacosLoadBalancer(
loadBalancerClientFactory.getLazyProvider(name,
ServiceInstanceListSupplier.class),
name, nacosDiscoveryProperties);
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnReactiveDiscoveryEnabled
@Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER)
public static class ReactiveSupportConfiguration {

@Bean
@ConditionalOnBean(ReactiveDiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true)
public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder().withDiscoveryClient()
.build(context);
}

@Bean
@ConditionalOnBean(ReactiveDiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference")
public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder().withDiscoveryClient()
.withZonePreference().build(context);
}

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnBlockingDiscoveryEnabled
@Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER + 1)
public static class BlockingSupportConfiguration {

@Bean
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true)
public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
.build(context);
}

@Bean
@ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference")
public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
.withZonePreference().build(context);
}

}

}

标签:01,return,String,nacos,instance,nacosDiscoveryProperties,registration,public
From: https://blog.51cto.com/u_15847681/5798034

相关文章

  • Ye Yuan-2019-DiverseTrajectoryForecastingWithDeterminantalPointProcesses
    #DiverseTrajectoryForecastingwithDeterminantalPointProcesses#paper1.paper-info1.1MetadataAuthor::[[YeYuan]],[[KrisKitani]]作者机构::Carne......
  • nacos——00
    具体版本参见​​spring-cloud-alibaba版本说明​​这里采用2021.0.4.0*,对应nacos版本2.0.4这里是个开头,后续更新nacos相关流程。......
  • not_the_same_3dsctf_2016
    【Write-up】BUUCTFnot_the_same_3dsctf_2016原题链接【Write-up】BUUCTFnot_the_same_3dsctf_2016checksec查看程序架构ida查看程序伪代码构建exp完整exp......
  • xman_2019_format
    【Write-up】BUUCTFxman_2019_format原题链接【Write-up】BUUCTFxman_2019_formatchecksec查看程序架构ida查看程序伪代码构建expASLR对栈的影响构建地址链爆......
  • pwn2_sctf_2016
    "【符号位漏洞+ret2libc】【Write-up】BUUCTFpwn2_sctf_2016原题链接"【符号位漏洞+ret2libc】【Write-up】BUUCTFpwn2_sctf_2016checksec查看程序架构ida查看程序......
  • ciscn_2019_en_2
    【Write-up】BUUCTFciscn_2019_en_2原题链接和这道题是一道题,一模一样的【Write-up】BUUCTFciscn_2019_en_2checksec查看程序架构ida查看程序伪代码构建exp......
  • babyheap_0ctf_2017
    【Write-up】BUUCTFbabyheap_0ctf_2017原题链接这一题是作者的第一道堆题,给作者的第一感受就是神乎其神,在参考了网络上的一些WP后写下自己的WP,如有错误烦请斧正......
  • ciscn_2019_es_2
    【栈迁移例题解析】【Write-up】BUUCTFciscn_2019_es_2原题链接【栈迁移例题解析】【Write-up】BUUCTFciscn_2019_es_2checksec查看程序架构ida查看程序伪代码构......
  • 20201302姬正坤cat user
    数据块:超级快用来储存文件系统本身的信息inode结点:存放节点,储存文件属性、所有者、权限等信息数据区:分块存储文件数据,不连续存储存储模式示意......
  • 指针初阶001
    1.指针是什么?2.指针和指针类型3.野指针4.指针运算5.指针和数组6.二级指针7.指针数组++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++......