com.ecwid.consul.v1.Response.getConsulIndex()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(82)

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

Response.getConsulIndex介绍

暂无

代码示例

代码示例来源:origin: alipay/sofa-rpc

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNotBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
      .withValue(router)//
      .withConsulIndex(orgResponse.getConsulIndex())//
      .withConsulLastContact(orgResponse.getConsulLastContact())//
      .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
      .build();
    return response;
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNotBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
      .withValue(router)//
      .withConsulIndex(orgResponse.getConsulIndex())//
      .withConsulLastContact(orgResponse.getConsulLastContact())//
      .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
      .build();
    return response;
  }
  return null;
}

代码示例来源:origin: weibocom/motan

newResponse = new ConsulResponse<List<ConsulService>>();
newResponse.setValue(ConsulServices);
newResponse.setConsulIndex(orgResponse.getConsulIndex());
newResponse.setConsulLastContact(orgResponse
    .getConsulLastContact());

代码示例来源:origin: alipay/sofa-rpc

public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
  if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
    List<HealthService> healthServices = orgResponse.getValue();
    List<ConsulService> consulServices = Lists.newArrayList();
    for (HealthService orgService : healthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newService()//
        .withAddress(org.getAddress())//
        .withName(org.getService())//
        .withId(org.getId())//
        .withPort(org.getPort().toString())//
        .withTags(org.getTags())//
        .build();
      consulServices.add(newService);
    }
    if (!consulServices.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
        .withValue(consulServices)//
        .withConsulIndex(orgResponse.getConsulIndex())//
        .withConsulLastContact(orgResponse.getConsulLastContact())//
        .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
        .build();
      return response;
    }
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
  if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
    List<HealthService> healthServices = orgResponse.getValue();
    List<ConsulService> consulServices = Lists.newArrayList();
    for (HealthService orgService : healthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newService()//
        .withAddress(org.getAddress())//
        .withName(org.getService())//
        .withId(org.getId())//
        .withPort(org.getPort().toString())//
        .withTags(org.getTags())//
        .build();
      consulServices.add(newService);
    }
    if (!consulServices.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
        .withValue(consulServices)//
        .withConsulIndex(orgResponse.getConsulIndex())//
        .withConsulLastContact(orgResponse.getConsulLastContact())//
        .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
        .build();
      return response;
    }
  }
  return null;
}

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

private void setLastIndex(Response<?> response) {
  Long consulIndex = response.getConsulIndex();
  if (consulIndex != null) {
    lastIndex.set(response.getConsulIndex());
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-consul-binder

private void setLastIndex(Response<?> response) {
  Long consulIndex = response.getConsulIndex();
  if (consulIndex != null) {
    lastIndex.set(response.getConsulIndex());
  }
}

代码示例来源:origin: org.irenical.consul/archaius-consul

private Response<List<GetValue>> updateIndex(Response<List<GetValue>> response) {
  if (response != null) {
    this.latestIndex.set(response.getConsulIndex());
  }
  return response;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-consul-bus

private void setLastIndex(Response<?> response) {
  Long consulIndex = response.getConsulIndex();
  if (consulIndex != null) {
    lastIndex.set(BigInteger.valueOf(consulIndex));
  }
}

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

@Timed(value ="consul.watch-catalog-services")
  public void catalogServicesWatch() {
    try {
      long index = -1;
      if (catalogServicesIndex.get() != null) {
        index = catalogServicesIndex.get().longValue();
      }

      Response<Map<String, List<String>>> response = consul
          .getCatalogServices(new QueryParams(properties
              .getCatalogServicesWatchTimeout(), index), properties.getAclToken());
      Long consulIndex = response.getConsulIndex();
      if (consulIndex != null) {
        catalogServicesIndex.set(BigInteger.valueOf(consulIndex));
      }

      if (log.isTraceEnabled()) {
        log.trace("Received services update from consul: "+response.getValue()
                +", index: "+ consulIndex);
      }
      publisher.publishEvent(new HeartbeatEvent(this, consulIndex));
    }
    catch (Exception e) {
      log.error("Error watching Consul CatalogServices", e);
    }
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-consul-discovery

@Timed(value ="consul.watch-catalog-services")
  public void catalogServicesWatch() {
    try {
      long index = -1;
      if (catalogServicesIndex.get() != null) {
        index = catalogServicesIndex.get().longValue();
      }

      Response<Map<String, List<String>>> response = consul
          .getCatalogServices(new QueryParams(properties
              .getCatalogServicesWatchTimeout(), index), properties.getAclToken());
      Long consulIndex = response.getConsulIndex();
      if (consulIndex != null) {
        catalogServicesIndex.set(BigInteger.valueOf(consulIndex));
      }

      if (log.isTraceEnabled()) {
        log.trace("Received services update from consul: "+response.getValue()
                +", index: "+ consulIndex);
      }
      publisher.publishEvent(new HeartbeatEvent(this, consulIndex));
    }
    catch (Exception e) {
      log.error("Error watching Consul CatalogServices", e);
    }
  }
}

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

Long newIndex = response.getConsulIndex();

代码示例来源:origin: darren-fu/pampas

if (lastCatalogIndex != catalogServices.getConsulIndex()) {
  for (Map.Entry<String, List<String>> entry : catalogServices.getValue().entrySet()) {
    instancesMap.putIfAbsent(entry.getKey(), Collections.emptyList());
lastCatalogIndex = catalogServices.getConsulIndex();
for (String serviceName : instancesMap.keySet()) {
  Response<List<CatalogService>> catalogService = consulClient.getCatalogService(serviceName, QueryParams.DEFAULT);

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

public void init() {
  if (!this.context.endsWith("/")) {
    this.context = this.context + "/";
  }
  Response<List<GetValue>> response = source.getKVValues(context,
      configProperties.getAclToken(), QueryParams.DEFAULT);
  initialIndex = response.getConsulIndex();
  final List<GetValue> values = response.getValue();
  ConsulConfigProperties.Format format = configProperties.getFormat();
  switch (format) {
  case KEY_VALUE:
    parsePropertiesInKeyValueFormat(values);
    break;
  case PROPERTIES:
  case YAML:
    parsePropertiesWithNonKeyValueFormat(values, format);
  }
}

代码示例来源:origin: com.alipay.sofa/sofa-rpc-all

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNotBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
      .withValue(router)//
      .withConsulIndex(orgResponse.getConsulIndex())//
      .withConsulLastContact(orgResponse.getConsulLastContact())//
      .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
      .build();
    return response;
  }
  return null;
}

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

if (this.properties.getFormat() == FILES) {
  Response<GetValue> response = this.consul.getKVValue(propertySourceContext, this.properties.getAclToken());
  addIndex(propertySourceContext, response.getConsulIndex());
  if (response.getValue() != null) {
    ConsulFilesPropertySource filesPropertySource = new ConsulFilesPropertySource(propertySourceContext, this.consul, this.properties);

代码示例来源:origin: venus-boot/saluki

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNoneBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
                          .withValue(router)//
                          .withConsulIndex(orgResponse.getConsulIndex())//
                          .withConsulLastContact(orgResponse.getConsulLastContact())//
                          .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
                          .build();
    return response;
  }
  return null;
}

代码示例来源:origin: com.weibo/motan-registry-consul

newResponse = new ConsulResponse<List<ConsulService>>();
newResponse.setValue(ConsulServices);
newResponse.setConsulIndex(orgResponse.getConsulIndex());
newResponse.setConsulLastContact(orgResponse
    .getConsulLastContact());

代码示例来源:origin: venus-boot/saluki

public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
  if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
    List<HealthService> HealthServices = orgResponse.getValue();
    List<ConsulService> ConsulServcies = Lists.newArrayList();
    for (HealthService orgService : HealthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newSalukiService()//
                          .withAddress(org.getAddress())//
                          .withName(org.getService())//
                          .withId(org.getId())//
                          .withPort(org.getPort().toString())//
                          .withTags(org.getTags())//
                          .build();
      ConsulServcies.add(newService);
    }
    if (!ConsulServcies.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
                             .withValue(ConsulServcies)//
                             .withConsulIndex(orgResponse.getConsulIndex())//
                             .withConsulLastContact(orgResponse.getConsulLastContact())//
                             .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
                             .build();
      return response;
    }
  }
  return null;
}

代码示例来源:origin: com.alipay.sofa/sofa-rpc-all

public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
  if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
    List<HealthService> healthServices = orgResponse.getValue();
    List<ConsulService> consulServices = Lists.newArrayList();
    for (HealthService orgService : healthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newService()//
        .withAddress(org.getAddress())//
        .withName(org.getService())//
        .withId(org.getId())//
        .withPort(org.getPort().toString())//
        .withTags(org.getTags())//
        .build();
      consulServices.add(newService);
    }
    if (!consulServices.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
        .withValue(consulServices)//
        .withConsulIndex(orgResponse.getConsulIndex())//
        .withConsulLastContact(orgResponse.getConsulLastContact())//
        .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
        .build();
      return response;
    }
  }
  return null;
}

相关文章