Skip to content

Commit

Permalink
Add listener example
Browse files Browse the repository at this point in the history
  • Loading branch information
stfndamjanovic committed Jan 18, 2024
1 parent 9450ae5 commit da8330c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ $breaker = CircuitBreaker::for('test-service')

### Listeners

You can add listeners for circuit breaker actions. In order to do that, you should extend `CircuitBreakerListener` class.

```php
use Stfn\CircuitBreaker\CircuitBreakerListener;

class Logger extends CircuitBreakerListener
{
public function onSuccess($result): void
{
Log::info($result);
}

public function onFail($exception) : void
{
Log::info($exception);
}
}
```

And after that you can attach that listener to circuit breaker.

```php
$loggerListener = new Logger();

$breaker = CircuitBreaker::for('test-service')
->listeners([$loggerListener]);
```

## Testing

```bash
Expand Down

0 comments on commit da8330c

Please sign in to comment.