您好,登錄后才能下訂單哦!
consul中NewService的作用是什么,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
consul-api-1.4.1-sources.jar!/com/ecwid/consul/v1/agent/model/NewService.java
public class NewService { @SerializedName("ID") private String id; @SerializedName("Name") private String name; @SerializedName("Tags") private List<String> tags; @SerializedName("Address") private String address; @SerializedName("Meta") private Map<String, String> meta; @SerializedName("Port") private Integer port; @SerializedName("EnableTagOverride") private Boolean enableTagOverride; @SerializedName("Check") private Check check; @SerializedName("Checks") private List<Check> checks; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<String> getTags() { return tags; } public void setTags(List<String> tags) { this.tags = tags; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public Map<String, String> getMeta() { return meta; } public void setMeta(Map<String, String> meta) { this.meta = meta; } public Integer getPort() { return port; } public void setPort(Integer port) { this.port = port; } public Boolean getEnableTagOverride() { return enableTagOverride; } public void setEnableTagOverride(Boolean enableTagOverride) { this.enableTagOverride = enableTagOverride; } public Check getCheck() { return check; } public void setCheck(Check check) { this.check = check; } public List<Check> getChecks() { return checks; } public void setChecks(List<Check> checks) { this.checks = checks; } @Override public String toString() { return "NewService{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", tags=" + tags + ", address='" + address + '\'' + ", meta=" + meta + ", port=" + port + ", enableTagOverride=" + enableTagOverride + ", check=" + check + ", checks=" + checks + '}'; } }
NewService定義了id、name、tags、address、meta、port、enableTagOverride、check、checks屬性
consul-api-1.4.1-sources.jar!/com/ecwid/consul/v1/agent/model/NewService.java
public static class Check { @SerializedName("Script") private String script; @SerializedName("Interval") private String interval; @SerializedName("TTL") private String ttl; @SerializedName("HTTP") private String http; @SerializedName("Method") private String method; @SerializedName("Header") private Map<String, List<String>> header; @SerializedName("TCP") private String tcp; @SerializedName("Timeout") private String timeout; @SerializedName("DeregisterCriticalServiceAfter") private String deregisterCriticalServiceAfter; @SerializedName("TLSSkipVerify") private Boolean tlsSkipVerify; @SerializedName("Status") private String status; public String getScript() { return script; } public void setScript(String script) { this.script = script; } public String getInterval() { return interval; } public void setInterval(String interval) { this.interval = interval; } public String getTtl() { return ttl; } public void setTtl(String ttl) { this.ttl = ttl; } public String getHttp() { return http; } public void setHttp(String http) { this.http = http; } public String getMethod() { return method; } public void setMethod(String method) { this.method = method; } public Map<String, List<String>> getHeader() { return header; } public void setHeader(Map<String, List<String>> header) { this.header = header; } public String getTcp() { return tcp; } public void setTcp(String tcp) { this.tcp = tcp; } public String getTimeout() { return timeout; } public void setTimeout(String timeout) { this.timeout = timeout; } public String getDeregisterCriticalServiceAfter() { return deregisterCriticalServiceAfter; } public void setDeregisterCriticalServiceAfter(String deregisterCriticalServiceAfter) { this.deregisterCriticalServiceAfter = deregisterCriticalServiceAfter; } public Boolean getTlsSkipVerify() { return tlsSkipVerify; } public void setTlsSkipVerify(Boolean tlsSkipVerify) { this.tlsSkipVerify = tlsSkipVerify; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } @Override public String toString() { return "Check{" + "script='" + script + '\'' + ", interval='" + interval + '\'' + ", ttl='" + ttl + '\'' + ", http='" + http + '\'' + ", method='" + method + '\'' + ", header=" + header + ", tcp='" + tcp + '\'' + ", timeout='" + timeout + '\'' + ", deregisterCriticalServiceAfter='" + deregisterCriticalServiceAfter + '\'' + ", tlsSkipVerify=" + tlsSkipVerify + ", status='" + status + '\'' + '}'; } }
NewService.Check定義了script、interval、ttl、http、method、header、tcp、timeout、deregisterCriticalServiceAfter、tlsSkipVerify、status屬性
consul-api-1.4.1-sources.jar!/com/ecwid/consul/v1/agent/AgentConsulClient.java
public final class AgentConsulClient implements AgentClient { private final ConsulRawClient rawClient; //...... public Response<Void> agentServiceRegister(NewService newService) { return agentServiceRegister(newService, null); } public Response<Void> agentServiceRegister(NewService newService, String token) { UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null; String json = GsonFactory.getGson().toJson(newService); RawResponse rawResponse = rawClient.makePutRequest("/v1/agent/service/register", json, tokenParam); if (rawResponse.getStatusCode() == 200) { return new Response<Void>(null, rawResponse); } else { throw new OperationException(rawResponse); } } //...... }
AgentConsulClient的agentServiceRegister方法使用rawClient向/v1/agent/service/register
這個url發送put請求,把newService的json數據發送過去
NewService定義了id、name、tags、address、meta、port、enableTagOverride、check、checks屬性
NewService.Check定義了script、interval、ttl、http、method、header、tcp、timeout、deregisterCriticalServiceAfter、tlsSkipVerify、status屬性
AgentConsulClient的agentServiceRegister方法使用rawClient向/v1/agent/service/register
這個url發送put請求,把newService的json數據發送過去
看完上述內容,你們掌握consul中NewService的作用是什么的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。