gpt4 book ai didi

com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 21:00:03 32 4
gpt4 key购买 nike

本文整理了Java中com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver类的一些代码示例,展示了ZoneAffinityClusterResolver类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneAffinityClusterResolver类的具体详情如下:
包路径:com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver
类名称:ZoneAffinityClusterResolver

ZoneAffinityClusterResolver介绍

[英]It is a cluster resolver that reorders the server list, such that the first server on the list is in the same zone as the client. The server is chosen randomly from the available pool of server in that zone. The remaining servers are appended in a random order, local zone first, followed by servers from other zones.
[中]它是一个集群解析程序,可以对服务器列表进行重新排序,以便列表中的第一台服务器与客户端位于同一区域。服务器是从该区域的可用服务器池中随机选择的。其余的服务器按随机顺序追加,首先是本地区域,然后是其他区域的服务器。

代码示例

代码示例来源:origin: Netflix/eureka

new ZoneAffinityClusterResolver(compositeResolver, myZone, true),
transportConfig.getAsyncExecutorThreadPoolSize(),
transportConfig.getAsyncResolverRefreshIntervalMs(),

代码示例来源:origin: Netflix/eureka

@Override
public List<AwsEndpoint> getClusterEndpoints() {
  List<AwsEndpoint>[] parts = ResolverUtils.splitByZone(delegate.getClusterEndpoints(), myZone);
  List<AwsEndpoint> myZoneEndpoints = parts[0];
  List<AwsEndpoint> remainingEndpoints = parts[1];
  List<AwsEndpoint> randomizedList = randomizeAndMerge(myZoneEndpoints, remainingEndpoints);
  if (!zoneAffinity) {
    Collections.reverse(randomizedList);
  }
  logger.debug("Local zone={}; resolved to: {}", myZone, randomizedList);
  return randomizedList;
}

代码示例来源:origin: Netflix/eureka

@Test
public void testAntiAffinity() throws Exception {
  List<AwsEndpoint> endpoints = SampleCluster.merge(SampleCluster.UsEast1a, SampleCluster.UsEast1b);
  ZoneAffinityClusterResolver resolver = new ZoneAffinityClusterResolver(new StaticClusterResolver<>("regionA", endpoints), "us-east-1b", false);
  List<AwsEndpoint> result = resolver.getClusterEndpoints();
  assertThat(result.size(), is(equalTo(endpoints.size())));
  assertThat(result.get(0).getZone(), is(equalTo("us-east-1a")));
}

代码示例来源:origin: Netflix/eureka

@Override
public ClusterResolver<AwsEndpoint> createClusterResolver() {
  ClusterResolver<AwsEndpoint> newResolver;
  if (clientConfig.shouldUseDnsForFetchingServiceUrls()) {
    String discoveryDnsName = "txt." + myRegion + '.' + clientConfig.getEurekaServerDNSName();
    newResolver = new DnsTxtRecordClusterResolver(
        myRegion,
        discoveryDnsName,
        true,
        Integer.parseInt(clientConfig.getEurekaServerPort()),
        false,
        clientConfig.getEurekaServerURLContext()
    );
    newResolver = new ZoneAffinityClusterResolver(newResolver, myZone, clientConfig.shouldPreferSameZoneEureka());
  } else {
    // FIXME Not randomized in the EndpointUtils.getServiceUrlsFromConfig, and no zone info to do this here
    newResolver = new StaticClusterResolver<>(myRegion, createEurekaEndpointsFromConfig());
  }
  return newResolver;
}

代码示例来源:origin: Netflix/eureka

@Test
  public void testUnrecognizedZoneIsIgnored() throws Exception {
    List<AwsEndpoint> endpoints = SampleCluster.merge(SampleCluster.UsEast1a, SampleCluster.UsEast1b);

    ZoneAffinityClusterResolver resolver = new ZoneAffinityClusterResolver(new StaticClusterResolver<>("regionA", endpoints), "us-east-1c", true);

    List<AwsEndpoint> result = resolver.getClusterEndpoints();
    assertThat(result.size(), is(equalTo(endpoints.size())));
  }
}

代码示例来源:origin: com.netflix.eureka/eureka-client

@Override
public List<AwsEndpoint> getClusterEndpoints() {
  List<AwsEndpoint>[] parts = ResolverUtils.splitByZone(delegate.getClusterEndpoints(), myZone);
  List<AwsEndpoint> myZoneEndpoints = parts[0];
  List<AwsEndpoint> remainingEndpoints = parts[1];
  List<AwsEndpoint> randomizedList = randomizeAndMerge(myZoneEndpoints, remainingEndpoints);
  if (!zoneAffinity) {
    Collections.reverse(randomizedList);
  }
  logger.debug("Local zone={}; resolved to: {}", myZone, randomizedList);
  return randomizedList;
}

代码示例来源:origin: Netflix/eureka

/**
 * @return a bootstrap resolver that resolves eureka server endpoints based on either DNS or static config,
 *         depending on configuration for one or the other. This resolver will warm up at the start.
 */
static ClosableResolver<AwsEndpoint> defaultBootstrapResolver(final EurekaClientConfig clientConfig,
                               final InstanceInfo myInstanceInfo) {
  String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
  String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
  ClusterResolver<AwsEndpoint> delegateResolver = new ZoneAffinityClusterResolver(
      new ConfigClusterResolver(clientConfig, myInstanceInfo),
      myZone,
      true
  );
  List<AwsEndpoint> initialValue = delegateResolver.getClusterEndpoints();
  if (initialValue.isEmpty()) {
    String msg = "Initial resolution of Eureka server endpoints failed. Check ConfigClusterResolver logs for more info";
    logger.error(msg);
    failFastOnInitCheck(clientConfig, msg);
  }
  return new AsyncResolver<>(
      EurekaClientNames.BOOTSTRAP,
      delegateResolver,
      initialValue,
      1,
      clientConfig.getEurekaServiceUrlPollIntervalSeconds() * 1000
  );
}

代码示例来源:origin: Netflix/eureka

@Test
public void testApplicationZoneIsFirstOnTheList() throws Exception {
  List<AwsEndpoint> endpoints = SampleCluster.merge(SampleCluster.UsEast1a, SampleCluster.UsEast1b, SampleCluster.UsEast1c);
  ZoneAffinityClusterResolver resolver = new ZoneAffinityClusterResolver(new StaticClusterResolver<>("regionA", endpoints), "us-east-1b", true);
  List<AwsEndpoint> result = resolver.getClusterEndpoints();
  assertThat(result.size(), is(equalTo(endpoints.size())));
  assertThat(result.get(0).getZone(), is(equalTo("us-east-1b")));
}

代码示例来源:origin: Netflix/eureka

new ZoneAffinityClusterResolver(compositeResolver, myZone, true),
initialValue,
transportConfig.getAsyncExecutorThreadPoolSize(),

代码示例来源:origin: com.netflix.eureka/eureka-client

new ZoneAffinityClusterResolver(compositeResolver, myZone, true),
transportConfig.getAsyncExecutorThreadPoolSize(),
transportConfig.getAsyncResolverRefreshIntervalMs(),

代码示例来源:origin: com.netflix.eureka/eureka-client

/**
 * @return a bootstrap resolver that resolves eureka server endpoints based on either DNS or static config,
 *         depending on configuration for one or the other. This resolver will warm up at the start.
 */
static ClosableResolver<AwsEndpoint> defaultBootstrapResolver(final EurekaClientConfig clientConfig,
                               final InstanceInfo myInstanceInfo) {
  String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
  String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
  ClusterResolver<AwsEndpoint> delegateResolver = new ZoneAffinityClusterResolver(
      new ConfigClusterResolver(clientConfig, myInstanceInfo),
      myZone,
      true
  );
  List<AwsEndpoint> initialValue = delegateResolver.getClusterEndpoints();
  if (initialValue.isEmpty()) {
    String msg = "Initial resolution of Eureka server endpoints failed. Check ConfigClusterResolver logs for more info";
    logger.error(msg);
    failFastOnInitCheck(clientConfig, msg);
  }
  return new AsyncResolver<>(
      EurekaClientNames.BOOTSTRAP,
      delegateResolver,
      initialValue,
      1,
      clientConfig.getEurekaServiceUrlPollIntervalSeconds() * 1000
  );
}

代码示例来源:origin: com.netflix.eureka/eureka-client

@Override
public ClusterResolver<AwsEndpoint> createClusterResolver() {
  ClusterResolver<AwsEndpoint> newResolver;
  if (clientConfig.shouldUseDnsForFetchingServiceUrls()) {
    String discoveryDnsName = "txt." + myRegion + '.' + clientConfig.getEurekaServerDNSName();
    newResolver = new DnsTxtRecordClusterResolver(
        myRegion,
        discoveryDnsName,
        true,
        Integer.parseInt(clientConfig.getEurekaServerPort()),
        false,
        clientConfig.getEurekaServerURLContext()
    );
    newResolver = new ZoneAffinityClusterResolver(newResolver, myZone, clientConfig.shouldPreferSameZoneEureka());
  } else {
    // FIXME Not randomized in the EndpointUtils.getServiceUrlsFromConfig, and no zone info to do this here
    newResolver = new StaticClusterResolver<>(myRegion, createEurekaEndpointsFromConfig());
  }
  return newResolver;
}

代码示例来源:origin: com.netflix.eureka/eureka-client

new ZoneAffinityClusterResolver(compositeResolver, myZone, true),
initialValue,
transportConfig.getAsyncExecutorThreadPoolSize(),

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com