2、POM

  1. <dependencies>
  2. <!--hystrix-->
  3. <dependency>
  4. <groupId>org.springframework.cloud</groupId>
  5. <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  6. </dependency>
  7. <!--eureka client-->
  8. <dependency>
  9. <groupId>org.springframework.cloud</groupId>
  10. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  11. </dependency>
  12. <!--web-->
  13. <dependency>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-starter-web</artifactId>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-starter-actuator</artifactId>
  20. </dependency>
  21. <dependency>
  22. <groupId>com.tfjy.springcloud</groupId>
  23. <artifactId>cloud-api-commons</artifactId>
  24. <version>1.0-SNAPSHOT</version>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-devtools</artifactId>
  29. <scope>runtime</scope>
  30. <optional>true</optional>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.projectlombok</groupId>
  34. <artifactId>lombok</artifactId>
  35. <optional>true</optional>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-starter-test</artifactId>
  40. <scope>test</scope>
  41. </dependency>
  42. </dependencies>

3、YML

  1. server:
  2. port: 8001
  3. spring:
  4. application:
  5. name: cloud-provider-hystrix-payment
  6. eureka:
  7. client:
  8. register-with-eureka: true
  9. fetch-registry: true
  10. service-url:
  11. #defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
  12. defaultZone: http://eureka7001.com:7001/eureka

4、主启动

image.png

5、业务类

  1. @Service
  2. public class PaymentService {
  3. /**
  4. * 正常访问
  5. * @param id
  6. * @return
  7. */
  8. public String paymentInfo_ok(Integer id){
  9. return "线程池:"+Thread.currentThread().getName()+"paymentInfo_ok,id"+id+"\t"+"O(∩_∩)O哈哈~";
  10. }
  11. public String paymentInfo_TimeOut(Integer id){
  12. try{
  13. TimeUnit.SECONDS.sleep(3);
  14. }catch (InterruptedException e){
  15. e.printStackTrace();
  16. }
  17. return "线程池:"+Thread.currentThread().getName()+"paymentInfo_TimeOut,id"+id+"O(∩_∩)O哈哈~"+"耗时3秒钟";
  18. }
  19. }
  1. @RestController
  2. @Slf4j
  3. public class PaymentController {
  4. @Resource
  5. private PaymentService paymentService;
  6. @Value("${server.port}")
  7. private String serverPort;
  8. @GetMapping("/payment/hystrix/ok/{id}")
  9. public String paymentInfo_OK(@PathVariable("id") Integer id){
  10. String result = paymentService.paymentInfo_ok(id);
  11. log.info("*****result"+result);
  12. return result;
  13. }
  14. @GetMapping("/payment/hystrix/timeout/{id}")
  15. public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
  16. String result = paymentService.paymentInfo_TimeOut(id);
  17. log.info("*****result"+result);
  18. return result;
  19. }
  20. }

6、正常测试

启动eureka7001
启动cloud-provider-hystrix-payment8001
访问
删除Module均OK

7、压力测试

开启Jmeter
然后两个都在转圈圈了

tomcat的默认工作线程数被打满了,