定制 lukaszaleckas/laravel-circuit-breaker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lukaszaleckas/laravel-circuit-breaker

Composer 安装命令:

composer require lukaszaleckas/laravel-circuit-breaker

包简介

README 文档

README

Circuit breaker is a design pattern used in software development. It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties.

Source: Wikipedia

Further explanation

Let's explain what this does using an example, as they are much better than definitions, in my opinion.

Let's say you have two microservices A and B:

  1. You are calling microservice B from A and have a 30s timeout configured.
  2. B fails to respond and you receive a timeout error.
  3. You keep getting requests to A and keep failing with a timeout from B.
  4. Request queue of A gets filled up.
  5. Requests to A start to timeout.

In this case it would be much better to track request failures from A to B and return an error immediately.

Circuit Breaker pattern does just that - on A you are tracking request failures to B and if failure count, in the particular time window, exceeds threshold, you skip doing those requests and return an error immediately.

Installation

  1. Run:
composer require lukaszaleckas/laravel-circuit-breaker

Service provider should be automatically registered, if not add

LaravelCircuitBreaker\CircuitBreakerServiceProvider::class

to your application's app.php.

  1. Publish circuit-breaker.php config file:
    php artisan vendor:publish --tag=circuit-breaker

Usage

Inject LaravelCircuitBreaker\CircuitBreakerService through constructor.

Use getCircuitBreaker with service name passed as a parameter to get a circuit breaker instance.

Method usage:

  • Use isClosed in your, for example, HTTP client to determine if requests can be made.
  • Use registerFailure when you receive an error.
  • Use registerSuccess when you receive a success response. This is used to close the circuit when/if it's half open.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-02-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固