搶先一步
VMware 提供培訓和認證,以加速您的進步。
瞭解更多Consul 是一個用於發現和配置基礎設施中服務的系統。 它由 Hashicorp 構建,與建立 Vagrant 和 Packer 的是同一批聰明人。 Consul 提供了服務發現、健康檢查、鍵/值儲存等服務,同時支援開箱即用的多資料中心。
Spring Cloud Consul 旨在將所有這些功能引入 Spring Cloud 生態系統。 該專案已達到其第一個里程碑,新鮮的 jar 包可在 repo.spring.io 儲存庫中找到。 Spring Cloud Consul 提供了以下功能
Spring Cloud Consul Discovery:Spring Cloud Commons DiscoveryClient
的實現。 服務註冊和發現透過 Consul HTTP API 執行。
Spring Cloud Consul Config:透過 Consul 鍵/值 API 進行分散式配置。 其行為類似於 Spring Cloud Config Client,但由分散式 Consul KV 儲存支援。
Spring Cloud Consul Bus:一個事件匯流排,用於透過分散式訊息傳遞將服務和服務例項連結在一起。 適用於在叢集中傳播狀態更改(例如,配置更改事件)。 這是使用 Consul Event API 實現的。
Spring Cloud Consul UI:Consul Web UI 的嵌入式版本。
以上所有內容都具有 1.0.0.M1 釋出標籤,要開始使用,請在您的 pom.xml
中包含以下工件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-config</artifactId>
<version>1.0.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-discovery</artifactId>
<version>1.0.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-bus</artifactId>
<version>1.0.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-ui</artifactId>
<version>1.0.0.M1</version>
</dependency>
按照文件確保已安裝並正在執行 Consul。
一個可能看起來像這樣的示例應用程式
@SpringBootApplication
@EnableDiscoveryClient
@EnableConsulUi
@RestController
public class SampleApp2 {
@RequestMapping("/")
public String hello() {
return "Hello World";
}
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
}
執行您的應用程式後,訪問 https://:8080/ui
以檢視 Consul UI。
程式碼 託管在 github 上,並且非常歡迎社群貢獻,所以快去看看吧。 spring-cloud-consul-sample 中有一個示例。 執行該示例的說明包含在 README 中。
#SpringOne 2GX 2015 即將到來! 儘早在 華盛頓特區的 SpringOne2GX 預訂您的位置。 超級早鳥價將於 6 月 12 日到期! 這是第一手瞭解所有正在發生的事情並提供直接反饋的最佳機會。 我將討論 Spring Cloud Consul,請此處 檢視未來的詳細資訊。 檢視最近的部落格文章,看看我的意思,還有更多內容即將推出!
#折扣