lemonde/php-circuit-breaker-bundle

此包已被放弃,不再维护。未建议替代包。

断路器到symfony

1.1.1 2017-06-06 10:44 UTC

This package is not auto-updated.

Last update: 2023-08-19 14:29:33 UTC


README

Build Status Build Status Scrutinizer Code Quality Code Coverage

描述

所有内容均采用MIT许可,除非另有说明。自行承担风险使用。

实现断路器模式,请参阅此处 https://martinfowler.com.cn/bliki/CircuitBreaker.html

您可以在这里找到法语解释 https://medium.com/eleven-labs/le-circuit-breaker-k%C3%A9sako-4763e13a4a03

如何安装?

要求

  • =PHP 7

  • use LoggerInterface
  • use CacheInterface
composer require lemonde/php-circuit-breaker-bundle:lastest

在您的 AppKernel.php 中添加

public function registerBundles()
    {
        $bundles = [
            ....
            new CircuitBreakerBundle\CircuitBreakerBundle(),
        ];

        return $bundles;
    }

在您的 config.yml 中添加

circuit_breaker:
    # Number fail possible in circuit breaker
    threshold: 5
    # Time in seconds resend call after circuit breaker is open
    timeout: 20

并在您的 config.yml 中添加 CacheInterface 的配置

framework:
    cache:
        app: cache.adapter.filesystem

如何使用?

在调用您的服务之前

if ($this->get('circuit.breaker')->isOpen('your-service')) {
    // If service is down
}

您需要为每次调用将服务状态发送到每个调用

// $status is bool
$this->get('dispatcher')->dispatch('circuit.breaker', new CircuitBreakerEvent('your-service', $status));

如何贡献?

您可以添加问题,并创建pull请求。 https://github.com/lemonde/php-circuit-breaker-bundle/blob/master/.github/CONTRIBUTING.md