本文整理了Java中com.ecwid.consul.v1.Response
类的一些代码示例,展示了Response
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response
类的具体详情如下:
包路径:com.ecwid.consul.v1.Response
类名称:Response
暂无
代码示例来源:origin: weibocom/motan
public List<String> getDatacenters() {
return consulClient.getCatalogDatacenters().getValue();
}
代码示例来源: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: 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: 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-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: org.springframework.cloud/spring-cloud-consul-binder
private void setLastIndex(Response<?> response) {
Long consulIndex = response.getConsulIndex();
if (consulIndex != null) {
lastIndex.set(response.getConsulIndex());
}
}
代码示例来源:origin: weibocom/motan
@Override
public List<String> getGroups() {
List<String> groups = new ArrayList<String>();
for (String dc : getDatacenters()) {
QueryParams queryParams = new QueryParams(dc);
Map<String, List<String>> serviceMap = consulClient.getCatalogServices(queryParams).getValue();
serviceMap.remove("consul");
for (String service : serviceMap.keySet()) {
groups.add(formatGroupName(dc, service));
}
}
return groups;
}
代码示例来源: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: 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: 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: weibocom/motan
/**
* 获取指定group的指令列表
*
* @param groupName
* @return
*/
@Override
public String getCommands(String groupName) {
Response<GetValue> response = consulClient.getKVValue(ConsulConstants.CONSUL_MOTAN_COMMAND + groupName);
GetValue value = response.getValue();
String command = "";
if (value != null && value.getValue() != null) {
command = new String(Base64.decodeBase64(value.getValue()));
}
return command;
}
代码示例来源:origin: weibocom/motan
serviceName, true, queryParams);
ConsulResponse<List<ConsulService>> newResponse = null;
if (orgResponse != null && orgResponse.getValue() != null
&& !orgResponse.getValue().isEmpty()) {
List<HealthService> HealthServices = orgResponse.getValue();
List<ConsulService> ConsulServices = new ArrayList<ConsulService>(
HealthServices.size());
newResponse = new ConsulResponse<List<ConsulService>>();
newResponse.setValue(ConsulServices);
newResponse.setConsulIndex(orgResponse.getConsulIndex());
newResponse.setConsulLastContact(orgResponse
.getConsulLastContact());
newResponse.setConsulKnownLeader(orgResponse
.isConsulKnownLeader());
代码示例来源: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);
for (CatalogService service : catalogService.getValue()) {
for (HealthService healthService : healthServices.getValue()) {
System.out.println("healthService:" + healthService.getService());
String host = findHost(healthService);
代码示例来源: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: weibocom/motan
/**
* 获取所有指令
*
* @return
*/
@Override
public List<JSONObject> getAllCommands() {
List<JSONObject> commands = new ArrayList<JSONObject>();
Response<List<GetValue>> response = consulClient.getKVValues(ConsulConstants.CONSUL_MOTAN_COMMAND);
List<GetValue> values = response.getValue();
if (values != null) {
for (GetValue value : values) {
JSONObject node = new JSONObject();
if (value.getValue() == null) {
continue;
}
String group = value.getKey().substring(ConsulConstants.CONSUL_MOTAN_COMMAND.length());
String command = new String(Base64.decodeBase64(value.getValue()));
node.put("group", group);
node.put("command", RpcCommandUtil.stringToCommand(command));
commands.add(node);
}
}
return commands;
}
代码示例来源: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
if (response.getValue() != null && !response.getValue().isEmpty()) {
Long newIndex = response.getConsulIndex();
代码示例来源:origin: weibocom/motan
@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
List<JSONObject> results = new ArrayList<JSONObject>();
List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
for (Check check : checks) {
String serviceId = check.getServiceId();
String[] strings = serviceId.split("-");
if (strings[1].equals(service)) {
Check.CheckStatus status = check.getStatus();
JSONObject node = new JSONObject();
if (nodeType.equals(status.toString())) {
node.put("host", strings[0]);
node.put("info", null);
results.add(node);
}
}
}
return results;
}
代码示例来源: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
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);
filesPropertySource.init(response.getValue());
propertySource = filesPropertySource;
内容来源于网络,如有侵权,请联系作者删除!