gpt4 book ai didi

org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 10:15:31 27 4
gpt4 key购买 nike

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

ZookeeperDiscoveryProperties介绍

[英]Properties related to Zookeeper's Service Discovery.
[中]与Zookeeper的服务发现相关的属性。

代码示例

代码示例来源:origin: com.ofg/micro-infra-spring-config

private static String rootWithoutStartingSlash(ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
  if (zookeeperDiscoveryProperties.getRoot().startsWith("/")) {
    return zookeeperDiscoveryProperties.getRoot().substring(1);
  }
  return zookeeperDiscoveryProperties.getRoot();
}

代码示例来源:origin: Nepxion/Discovery

@Override
  protected Object afterInitialization(ConfigurableApplicationContext applicationContext, Object bean, String beanName) throws BeansException {
    if (bean instanceof ZookeeperServiceRegistry) {
      ZookeeperServiceRegistry zookeeperServiceRegistry = (ZookeeperServiceRegistry) bean;

      return new ZookeeperServiceRegistryDecorator(zookeeperServiceRegistry, applicationContext);
    } else if (bean instanceof ZookeeperDiscoveryProperties) {
      ConfigurableEnvironment environment = applicationContext.getEnvironment();

      ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = (ZookeeperDiscoveryProperties) bean;
      zookeeperDiscoveryProperties.setPreferIpAddress(true);

      Map<String, String> metadata = zookeeperDiscoveryProperties.getMetadata();
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, ZookeeperConstant.DISCOVERY_PLUGIN);
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED, PluginContextAware.isDiscoveryControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED, PluginContextAware.isConfigRestControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY, PluginContextAware.getGroupKey(environment));
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONTEXT_PATH, PluginContextAware.getContextPath(environment));

      MetadataUtil.filter(metadata);

      return bean;
    } else {
      return bean;
    }
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Bean
  public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
    ZookeeperDiscoveryProperties properties = new ZookeeperDiscoveryProperties(inetUtils);
    // for bootstrap, registration is not needed, just discovery client
    properties.setRegister(false);
    return properties;
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Bean
@ConditionalOnMissingBean(ZookeeperRegistration.class)
public ServiceInstanceRegistration serviceInstanceRegistration(
    ApplicationContext context, ZookeeperDiscoveryProperties properties) {
  String appName = context.getEnvironment().getProperty("spring.application.name",
      "application");
  String host = properties.getInstanceHost();
  if (!StringUtils.hasText(host)) {
    throw new IllegalStateException("instanceHost must not be empty");
  }
  ZookeeperInstance zookeeperInstance = new ZookeeperInstance(context.getId(),
      appName, properties.getMetadata());
  RegistrationBuilder builder = ServiceInstanceRegistration.builder().address(host)
      .name(appName).payload(zookeeperInstance)
      .uriSpec(properties.getUriSpec());
  if (properties.getInstanceSslPort() != null) {
    builder.sslPort(properties.getInstanceSslPort());
  }
  if (properties.getInstanceId() != null) {
    builder.id(properties.getInstanceId());
  }
  // TODO add customizer?
  return builder.build();
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@PostConstruct
public void init() {
  if (this.properties == null || this.server == null) {
    return;
  }
  String prefix = this.server.getPrefix();
  if (StringUtils.hasText(prefix)) {
    this.properties.getMetadata().put("configPath", prefix);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Bean
@ConditionalOnMissingBean
public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
  return new ZookeeperDiscoveryProperties(inetUtils);
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

protected ServiceInstance serviceInstance(StubConfiguration stubConfiguration,
    int port) {
  try {
    return ServiceInstance.builder()
        .uriSpec(new UriSpec(this.zookeeperDiscoveryProperties.getUriSpec()))
        .address("localhost").port(port).name(name(stubConfiguration))
        .build();
  }
  catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

public ZookeeperAutoServiceRegistration(ZookeeperServiceRegistry registry,
                    ZookeeperRegistration registration,
                    ZookeeperDiscoveryProperties properties,
                    AutoServiceRegistrationProperties arProperties) {
  super(registry, arProperties);
  this.registration = registration;
  this.properties = properties;
  if (this.properties.getInstancePort() != null) {
    this.registration.setPort(this.properties.getInstancePort());
  }
}

代码示例来源:origin: SpringCloud/spring-cloud-gray

@Bean
  @ConditionalOnMissingBean
  public InstanceLocalInfo instanceLocalInfo(@Autowired Registration registration,
                        @Autowired ZookeeperDiscoveryProperties properties)
      throws ConfigurationException {
    String instanceId;
    if (properties.getMetadata().containsKey(METADATA_KEY_INSTANCE_ID)) {
      instanceId = properties.getMetadata().get(METADATA_KEY_INSTANCE_ID);
    } else {
      throw new ConfigurationException("Unable to find config spring.cloud.zookeeper.discovery.metadata" +
          ".instanceId!");
    }

    InstanceLocalInfo localInfo = new InstanceLocalInfo();
    localInfo.setInstanceId(instanceId);
    localInfo.setServiceId(registration.getServiceId());
    localInfo.setGray(false);
    return localInfo;
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Bean
  @ConditionalOnMissingBean
  public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
    return new ZookeeperDiscoveryProperties(inetUtils);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

private String prepareQueryName(String name) {
  String root = this.zookeeperDiscoveryProperties.getRoot();
  return name.startsWith(root) ? name : root + name;
}

代码示例来源:origin: com.nepxion/discovery-plugin-framework-zookeeper

@Override
  protected Object afterInitialization(ConfigurableApplicationContext applicationContext, Object bean, String beanName) throws BeansException {
    if (bean instanceof ZookeeperServiceRegistry) {
      ZookeeperServiceRegistry zookeeperServiceRegistry = (ZookeeperServiceRegistry) bean;

      return new ZookeeperServiceRegistryDecorator(zookeeperServiceRegistry, applicationContext);
    } else if (bean instanceof ZookeeperDiscoveryProperties) {
      ConfigurableEnvironment environment = applicationContext.getEnvironment();

      ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = (ZookeeperDiscoveryProperties) bean;
      zookeeperDiscoveryProperties.setPreferIpAddress(true);

      Map<String, String> metadata = zookeeperDiscoveryProperties.getMetadata();
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN, ZookeeperConstant.DISCOVERY_PLUGIN);
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_VERSION, DiscoveryConstant.DISCOVERY_VERSION);
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED, PluginContextAware.isRegisterControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED, PluginContextAware.isDiscoveryControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED, PluginContextAware.isConfigRestControlEnabled(environment).toString());
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY, PluginContextAware.getGroupKey(environment));
      metadata.put(DiscoveryConstant.SPRING_APPLICATION_CONTEXT_PATH, PluginContextAware.getContextPath(environment));

      MetadataUtil.filter(metadata);

      return bean;
    } else {
      return bean;
    }
  }
}

代码示例来源:origin: com.ofg/micro-infra-spring-config

@Bean
@ConditionalOnMissingBean
@Profile("springCloud")
ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
  return new ZookeeperDiscoveryProperties(inetUtils);
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

private String getPathWithoutRoot(String path) {
  return path.substring(this.zookeeperDiscoveryProperties.getRoot().length());
}

代码示例来源:origin: com.ofg/micro-infra-spring-base

@Bean
@Profile(PRODUCTION)
public MetricsBasePath metricsBasePath(@Value("${metrics.path.root:apps}") String rootName,
                    @Value("${metrics.path.environment:#{systemProperties['APP_ENV'] ?: 'test'}}") String environment,
                    @Value("spring.application.name") String springAppName,
                    @Value("${metrics.path.node:#{T(com.ofg.infrastructure.metrics.config.MetricsConfiguration).resolveLocalHostName()}}") String node) {
  String basePath = zookeeperDiscoveryProperties != null ? zookeeperDiscoveryProperties.getRoot() : serviceConfigurationResolver.getBasePath();
  String applicationName = zookeeperDiscoveryProperties != null ? getLastName(springAppName) : serviceConfigurationResolver.getMicroservicePath().getLastName();
  String country = env.getProperty("metrics.path.country", basePath);
  String appName = env.getProperty("metrics.path.app", applicationName);
  return new EnvironmentAwareMetricsBasePath(rootName, environment, country, appName, node);
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Override
  public ServiceDiscovery<ZookeeperInstance> customize(ServiceDiscoveryBuilder<ZookeeperInstance> builder) {
    // @formatter:off
    return builder
        .client(this.curator)
        .basePath(this.properties.getRoot())
        .serializer(this.instanceSerializer)
        .build();
    // @formatter:on
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

protected ServiceDiscovery serviceDiscovery(ServiceInstance serviceInstance) {
  return ServiceDiscoveryBuilder.builder(Void.class)
      .basePath(this.zookeeperDiscoveryProperties.getRoot())
      .client(this.curatorFramework).thisInstance(serviceInstance).build();
}

代码示例来源:origin: spring-cloud/spring-cloud-zookeeper

@Override
public void onApplicationEvent(InstanceRegisteredEvent<?> event) {
  this.cache = TreeCache.newBuilder(this.curator, this.properties.getRoot()).build();
  this.cache.getListenable().addListener(this);
  try {
    this.cache.start();
  }
  catch (Exception e) {
    ReflectionUtils.rethrowRuntimeException(e);
  }
}

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