熔断器

熔断器概念,请详看服务治理章节。

定义熔断器

继承CircuitBreaker类,配置属性信息。一个服务的熔断器名称要和连接池一致。

  1. /**
  2. * the breaker of user
  3. *
  4. * @Breaker("user")
  5. */
  6. class UserBreaker extends CircuitBreaker
  7. {
  8. /**
  9. * The number of successive failures
  10. * If the arrival, the state switch to open
  11. *
  12. * @Value(name="${config.breaker.user.failCount}", env="${USER_BREAKER_FAIL_COUNT}")
  13. * @var int
  14. */
  15. protected $switchToFailCount = 3;
  16. /**
  17. * The number of successive successes
  18. * If the arrival, the state switch to close
  19. *
  20. * @Value(name="${config.breaker.user.successCount}", env="${USER_BREAKER_SUCCESS_COUNT}")
  21. * @var int
  22. */
  23. protected $switchToSuccessCount = 3;
  24. /**
  25. * Switch close to open delay time
  26. * The unit is milliseconds
  27. *
  28. * @Value(name="${config.breaker.user.delayTime}", env="${USER_BREAKER_DELAY_TIME}")
  29. * @var int
  30. */
  31. protected $delaySwitchTimer = 500;
  32. }