7.3.6 Retry and Circuit Breaker

Recovering from failure is critical for HTTP clients, and that is where Micronaut’s integrated Retry Advice comes in handy.

You can declare the @Retryable or @CircuitBreaker annotations on any @Client interface and the retry policy will be applied, for example:

Declaring @Retryable

  1. @Client("/pets")
  2. @Retryable
  3. public interface PetClient extends PetOperations {
  4. @Override
  5. @SingleResult
  6. Publisher<Pet> save(String name, int age);
  7. }

Declaring @Retryable

  1. @Client("/pets")
  2. @Retryable
  3. interface PetClient extends PetOperations {
  4. @Override
  5. Mono<Pet> save(String name, int age)
  6. }

Declaring @Retryable

  1. @Client("/pets")
  2. @Retryable
  3. interface PetClient : PetOperations {
  4. override fun save(name: String, age: Int): Mono<Pet>
  5. }

For more information on customizing retry, see the section on Retry Advice.