---
agentTools:
  projectIndex: https://resilience4j.readme.io/llms.txt
---

# Examples

Examples of resilience4j-rxjava2

[block:api-header]
{
  "title": "Decorate Flowable with a CircuitBreaker"
}
[/block]

The following example shows how to decorate an Observable by using the custom RxJava operator. All other reactive types like Observable, Flowable, Single, Maybe and Completable are also supported.

The `CircuitBreakerOperator` checks if a downstream subscriber/observer can acquire a permission to subscribe to an upstream Publisher. If the CircuitBreaker is OPEN, the CircuitBreakerOperator emits a `CallNotPermittedException` to the downstream subscriber.

[block:code]
{
  "codes": [
    {
      "code": "CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults(\"name\");\nFlowable.fromCallable(backendService::doSomething)\n    .compose(CircuitBreakerOperator.of(circuitBreaker))",
      "language": "java"
    }
  ]
}
[/block]

[block:api-header]
{
  "title": "Decorate Flowable with a RateLimiter"
}
[/block]

The following example shows how to decorate a Flowable by using the custom RxJava2 operator.
All other reactive types like Flowable, Single, Maybe and Completable are also supported.

The `RateLimiterOperator` checks if a downstream subscriber/observer can acquire a permission to subscribe to an upstream Publisher. If the rate limit is exceeded, the RateLimiterOperator emits a `RequestNotPermitted` to the downstream subscriber.

[block:code]
{
  "codes": [
    {
      "code": "RateLimiter rateLimiter = RateLimiter.ofDefaults(\"name\");\nFlowable.fromCallable(backendService::doSomething)\n    .compose(RateLimiterOperator.of(rateLimiter))",
      "language": "java"
    }
  ]
}
[/block]

[block:api-header]
{
  "title": "Decorate Flowable with a Bulkhead"
}
[/block]

The following example shows how to decorate a Flowable by using the custom RxJava2 operator.
All other reactive types like Flowable, Single, Maybe and Completable are also supported.

The `BulkheadOperator` checks if a downstream subscriber/observer can acquire a permission to subscribe to an upstream Publisher. If the Bulhead is full, the BulkheadOperator emits a `BulkheadFullException` to the downstream subscriber.

[block:code]
{
  "codes": [
    {
      "code": "Bulkhead bulkhead = Bulkhead.ofDefaults(\"name\");\nFlowable.fromCallable(backendService::doSomething)\n  .compose(BulkheadOperator.of(bulkhead));",
      "language": "java",
      "name": null
    }
  ]
}
[/block]

[block:api-header]
{
  "title": "Decorate Flowable with Retry"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "Retry retry = Retry.ofDefaults(\"backendName\");\nFlowable.fromCallable(backendService::doSomething)\n    .compose(RetryOperator.of(retry))",
      "language": "java"
    }
  ]
}
[/block]