Skip to content

Latest commit

 

History

History

lab03

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

实验三、Spring Cloud Hystrix实验

实验步骤

1. 将student和school微服务项目导入Eclipse IDE

注意:school项目依赖

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

2. 运行student-springboot微服务项目

3. 运行school-springboot微服务项目

通过postman调用school微服务

http://localhost:8088/getSchoolDetails/abcschool

修改io.spring2go.hystrixlab.schoolservice.delegate.StudentServiceDelegateStudentServiceDelegate方法上的标注,依次实验各种Hystrix Command标注用法:

  1. 简单用法
	 @HystrixCommand
  1. 定制超时
    @HystrixCommand(commandProperties = {
    		@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "4000") })
  1. 定制降级方法
    @HystrixCommand(fallbackMethod = "callStudentService_Fallback")
  1. 定制线程池隔离策略
	@HystrixCommand(fallbackMethod = "callStudentService_Fallback",
			threadPoolKey = "studentServiceThreadPool",
			threadPoolProperties = {
					@HystrixProperty(name="coreSize", value="30"),
					@HystrixProperty(name="maxQueueSize", value="10")
			}
			)
  1. 查看hystrix stream和dashboard

hystrix stream:

http://localhost:8088/hystrix.stream

hystrix dashboard

http://localhost:8088/hystrix