กังหันเป็นเครื่องมือสำหรับการรวมเซิร์ฟเวอร์เพื่อส่งข้อมูลสตรีมเหตุการณ์ ในการตรวจสอบ Hystrix สามารถตรวจสอบโหนดเดียวเท่านั้นและในการผลิตจริงพวกเขาเป็นกลุ่ม ดังนั้นกังหันสามารถใช้ในการตรวจสอบตัวชี้วัดของ Hystrix ในคลัสเตอร์และบริการ Hystrix สามารถค้นพบผ่านยูเรก้า
สร้างโครงการกังหันใหม่
TurbineApplication.java
แพ็คเกจกังหัน; นำเข้า org.springframework.boot.springapplication; นำเข้า org.springframework.boot.autoconfigure.springbootapplication; นำเข้า org.springframework.cloud.netflix.hystrix.enablehystrix; org.springframework.cloud.netflix.hystrix.dashboard.enablehystrixdashboard; นำเข้า org.springframework.cloud.netflix.turbine.enableturbine;/*** สร้างโดย Sai.luo บน 2017/4/26 */@springbootapplication@enableturbine@enablehystrix@enablehystrixdashboardpublic คลาส turbineApplication {โมฆะคงที่สาธารณะหลัก (สตริง [] args) {springapplication.run (turbineapplication.class, args); -pom.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/ XSI: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" <Project.build.sourceencoding> UTF-8 </project.build.sourceencoding> <java.version> 1.8 </java.version> </premerties> <carent> <roupid> org.springframework.boot </Groupid> <Sersion> 1.5.2.Release </Strement> <inelyPath/> <!-การค้นหาผู้ปกครองจากที่เก็บ-> </Parent> <การพึ่งพา> <!-การพึ่งพา Hystrix-> <การพึ่งพา> <roupId> org.springframework.cloud </Groupid> <roupId> org.springframework.cloud </groupid> <ratifactid> Spring-Cloud-Starter-Hystrix-Dashboard </artifactid> </derpendency> <! </permentency> </derctency> <การพึ่งพาการจัดการ> <การพึ่งพา> <การพึ่งพา> <roupId> org.springframework.cloud </groupid> <ratifactid> สปริง-คดเคี้ยว-พึ่งพาอาศัย </artifactid> </serdencyManagement> <uffle> <plugins> <plugin> <molinid> org.springframework.boot </groupId> <ratifactid> Spring-Boot-Maven-Plugin </artifactid> </plugin>
application.yml
ฤดูใบไม้ผลิ: แอปพลิเคชัน: ชื่อ: turbinesserver: พอร์ต: 8000Turbine: App-Config: สวัสดี, Helloclient ## ชื่อบริการที่ต้องมีการตรวจสอบ Aggregator: ClusterConfig: Main ## บริการคลัสเตอร์บริการที่ต้องตรวจสอบ ClusternameExpression: metadata ServiceUrl: defaultzone: http: // localhost: 8761/Eureka/
เริ่มบริการ
แอปพลิเคชันโครงการ HelloServiceEureka Application.yml เพิ่มการกำหนดค่าคลัสเตอร์
เปลี่ยน
ฤดูใบไม้ผลิ: แอปพลิเคชัน: ชื่อ: HelloServer: พอร์ต: 9001EUREKA: อินสแตนซ์: สัญญาเช่า-ต่ออายุภายใน-ในวินาที: 3 การเช่า-ระยะเวลาการปล่อย-ระยะเวลา: 5 metadata-map: คลัสเตอร์: ไคลเอนต์หลัก: ServiceUrl: defaultzone: http: // localhost: 8761/eureka com: Netflix: Eureka: ปิดการค้นพบ: ปิด
pom.xml เพิ่มแพ็คเกจการพึ่งพา Hystrix
<การพึ่งพา> <roupID> org.springframework.cloud </groupId> <ratifactid> Spring-Cloud-Starter-Hystrix </artifactId>
ในทำนองเดียวกัน Ribboneureka Project Application.yml เพิ่มการกำหนดค่าคลัสเตอร์
หลังจากการเปลี่ยนแปลงสิ่งต่อไปนี้
ฤดูใบไม้ผลิ: แอปพลิเคชัน: ชื่อ: HelloclientServer: พอร์ต: 20000eureka: อินสแตนซ์: สัญญาเช่า-ต่ออายุภายใน-ในวินาที: 3 สัญญาเช่า-การออก-ระยะเวลา-วินาที: 5 metadata-map: คลัสเตอร์: ไคลเอนต์หลัก: ServiceUrl: defaultzone: http: // localhost: 8761/eure com: Netflix: Eureka: ปิดการค้นพบ: ปิด
pom.xml เพิ่มแพ็คเกจการพึ่งพา Hystrix
Ribboneurekaapplication.java เพิ่มคำอธิบายประกอบ
@enablehystrix
เริ่มโครงการ
เยี่ยมชม LocalHost: 8000/Hystrixx เพื่อดูหน้า
หมายเหตุ: กังหันสามารถตรวจสอบบริการ Hystrix ไม่ใช่บริการ Hystrix และไม่สามารถตรวจสอบได้ ตัวอย่างเช่นแม้ว่าบริการสวัสดีจะถูกกำหนดค่าด้วยคลัสเตอร์ แต่ก็ไม่ได้ใช้ Hystrix ดังนั้นจึงไม่ได้รับการตรวจสอบ
ที่อยู่โครงการ https://github.com/luosai001/spring-cloud-sample/tree/master
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น