加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[bigdata-110] spring-cloud-06 Hystrix断路器

发布时间:2020-12-14 03:27:02 所属栏目:大数据 来源:网络整理
导读:1. Hystrix对服务过载进行控制。 2. 参考文献 https://github.com/dyc87112/SpringCloudBook/tree/master/hystrix-dashboard 3. 源码结构 ├── pom.xml ├── src │ ? ├── main │ ? │ ? ├── java │ ? │ ? │ ? └── com │ ? │ ? │ ? ? ?

1. Hystrix对服务过载进行控制。


2. 参考文献

https://github.com/dyc87112/SpringCloudBook/tree/master/hystrix-dashboard


3. 源码结构

├── pom.xml
├── src
│ ? ├── main
│ ? │ ? ├── java
│ ? │ ? │ ? └── com
│ ? │ ? │ ? ? ? └── brian
│ ? │ ? │ ? ? ? ? ? └── demo
│ ? │ ? │ ? ? ? ? ? ? ? └── demohystrix
│ ? │ ? │ ? ? ? ? ? ? ? ? ? └── App.java
│ ? │ ? └── resources
│ ? │ ? ? ? └── application.properties


4. pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	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>

	<groupId>com.brian.demo</groupId>
	<artifactId>demohystrix</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>demohystrix</name>
	<url>http://maven.apache.org</url>

	<parent>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-parent</artifactId>
		<version>Brixton.SR5</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<repositories>
		<repository>
			<id>my-nexus-central</id>
			<name>my local nexus</name>
			<url>http://localhost:8081/nexus/content/repositories/central/</url>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>never</updatePolicy>
			</releases>
		</repository>
	</repositories>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<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>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

5. App.java

package com.brian.demo.demohystrix;


import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@EnableHystrixDashboard
@SpringCloudApplication
public class App {

	public static void main(String[] args) {
		SpringApplication.run(App.class,args);
	}

}


6. application.properties

spring.application.name=hystrix-dashboard
server.port=2001


7. 编译打包

mvn clean package


8. 运行

java -jar target/demohystrix-0.0.1-SNAPSHOT.jar


9. 查看

9.1 这个是界面

http://localhost:2001/hystrix

9.2 这个是ping服务

http://localhost:2001/hystrix.stream

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读