Turbin adalah alat untuk mengumpulkan server untuk mengirim data aliran acara. Dalam pemantauan Hystrix, hanya satu node yang dapat dipantau, dan dalam produksi aktual, mereka adalah kelompok. Oleh karena itu, turbin dapat digunakan untuk memantau metrik hystrix di cluster, dan layanan Hystrix dapat ditemukan melalui Eureka.
Buat proyek turbin baru
TurbineApplication.java
Paket turbin; impor org.springframework.boot.springapplication; impor org.springframework.boot.autoconfigure.springbootApplication; impor org.springframework.cloud.netflix.hytrix.enableHystrix; imporstrix; org.springframework.cloud.netflix.hystrix.dashboard.enableHystrixDashboard; impor org.springframework.cloud.netflix.turbine.enableTurbine;/*** dibuat oleh sai.luo pada 2017/4/26. */@SpringbootApplication@enableTurbine@enableHystrix@enableHyStrixDashboardPublic kelas TurbineApplication {public static void main (string [] args) {springapplication.run (turbineApplication.class, args); }}pom.xml
<? Xml Version = "1.0" encoding = "UTF-8"?> <Project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>turbine</artifactId> <properties> <Project.build.sourceencoding> UTF-8 </project.build.sourceencoding> <Java.Version> 1.8 </java.version> </Properties> <partent> <trupter> org.springframework.boot </groupid> <ArtiFacTID> Spring-stas-bootter </version </groupid> <ArtiFacTid> Spring-boots-stas-starter. <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <!-- hystrix dependencies--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <!-- turnbine dependencies--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine</artifactId> </dependency> </dependency> </dependency> <dependencyManagement> <dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependency> </dependency> </dependency> </dependencyManagement> <build> <plugins> <plugin> <groupId> org.springframework.boot </groupid> <ArTifactId> spring-boot-maven-plugin </artifactid> </lugin> </lugin> </build> </project>
application.yml
Spring: Aplikasi: Nama: Turbinesserver: Port: 8000Turbin: App-Config: Hello, HelloClient ## Nama Layanan yang perlu dipantau agregator: clusterconfig: utama ## jasa cluster nama yang perlu dipantau. ServiceUrl: DefaultZone: http: // localhost: 8761/eureka/
Mulailah layanan
HelloServiceEureka Project Application.yml Menambahkan Konfigurasi Cluster
Berubah menjadi
spring: application: name: helloserver: port: 9001eureka: instance: lease-renewal-interval-in-seconds: 3 lease-expiration-duration-in-seconds: 5 metadata-map: cluster: main client: serviceUrl: defaultZone: http://localhost:8761/eureka/ registry-fetch-interval-seconds: 3logging: level: com: Netflix: Eureka: Off Discovery: Off
pom.xml menambahkan paket ketergantungan hystrix
<dependency> <GroupId> org.springframework.cloud </groupid> <ArTifactId> Spring-cloud-starter-hystrix </artifactid> </dependency>
Demikian pula, application proyek Ribboneureka.yml menambahkan konfigurasi cluster
Setelah perubahan, berikut ini
spring: application: name: helloClientserver: port: 20000eureka: instance: lease-renewal-interval-in-seconds: 3 lease-expiration-duration-in-seconds: 5 metadata-map: cluster: main client: serviceUrl: defaultZone: http://localhost:8761/eureka/ registry-fetch-interval-seconds: 3logging: level: com: Netflix: Eureka: Off Discovery: Off
pom.xml menambahkan paket ketergantungan hystrix
RibboneureKeApplication.java Tambahkan anotasi
@EnableHystrix
Mulai proyek
Kunjungi LocalHost: 8000/Hystrixx untuk melihat halaman
Catatan: Turbin hanya dapat memantau layanan Hystrix, bukan layanan Hystrix, dan tidak dapat memantau. Misalnya, meskipun layanan Hello dikonfigurasi dengan cluster, itu tidak menggunakan Hystrix, sehingga tidak akan dipantau.
Alamat proyek https://github.com/luosai001/spring-cloud-sample/tree/master
Di atas adalah semua konten artikel ini. Saya berharap ini akan membantu untuk pembelajaran semua orang dan saya harap semua orang akan lebih mendukung wulin.com.