PHPackages                             flix-tech/guzzle-circuit-breaker-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. flix-tech/guzzle-circuit-breaker-middleware

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

flix-tech/guzzle-circuit-breaker-middleware
===========================================

A Guzzle 6 middleware to integrate `ejsmont-artur/php-circuit-breaker`

1.0.1(8y ago)10165.7kMITPHP

Since Jul 14Pushed 8y ago4 watchersCompare

[ Source](https://github.com/flix-tech/guzzle-circuit-breaker-middleware)[ Packagist](https://packagist.org/packages/flix-tech/guzzle-circuit-breaker-middleware)[ RSS](/packages/flix-tech-guzzle-circuit-breaker-middleware/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Guzzle 6 Circuit-Breaker Middleware
===================================

[](#guzzle-6-circuit-breaker-middleware)

[![Build Status](https://camo.githubusercontent.com/75c41383f6d8f80e522b0d65f6295253a16a1fed0845fab0677d8d0b888a053d/68747470733a2f2f7472617669732d63692e6f72672f666c69782d746563682f67757a7a6c652d636972637569742d627265616b65722d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/flix-tech/guzzle-circuit-breaker-middleware)

This is a Guzzle 6 middleware that integrates .

### Contents

[](#contents)

- [Requirements](#requirements)
    - [Hard Dependencies](#dependencies)
- [Installation](#installation)
- [Usage](#usage)
    - [Example](#example)
- [Testing](#testing)
    - [Unit tests, Coding standards and static analysis](#unit-tests-coding-standards-and-static-analysis)
- [Contributing](#contributing)

Requirements
------------

[](#requirements)

### Dependencies

[](#dependencies)

DependencyVersionReason**`php`**~7.0Anything lower has (almost) reached EOL**`guzzlephp/promises`**~6.2Middlewares pass Promises around**`psr/http-message`**~1.0Standardization, doh**`ejsmont-artur/php-circuit-breaker`**~0.1Simple and robust Circuit Breaker implementation for PHPInstallation
------------

[](#installation)

This library is installed via [`composer`](http://getcomposer.org).

```
composer require "flix-tech/guzzle-circuit-breaker-middleware=~1.0"
```

Usage
-----

[](#usage)

> **NOTE**It is recommended that this middleware is on top of the stack so that if a service is unavailable, it can instantly reject without going further down the chain.

With the default configuration, this middleware will inspect the PSR-7 requests for either a transport option key `"circuit_breaker.requested_service_name"` exposed via `Middleware::CB_TRANSFER_OPTION_KEY` in the request options array, or a request header `"X-CB-Service-Name"` exposed via `Middleware::CB_SERVICE_NAME_HEADER`. You can pass an own service name extractor callable that takes the form `f(RequestInterface $request, array $requestOptions): string`.

The service name will be used to look up the availability in the circuit breaker. If it is not available, it will be instantly rejected with a [`CircuitBreakerIsClosedException`](src/Exception/CircuitIsClosedException.php).

If the request was successful, the middleware will report a success to the circuit breaker for the given service. Otherwise it will report a failure and pass the rejection further down the chain.

You can pass a custom exception map into the middleware with which you can control which exception types and values should actually trigger a failure report. I.e. a 404 might be a failed configuration issue and might not trigger failure reports. The exception map callback takes the form `f($rejectedValue): bool`.

Example
-------

[](#example)

```
