Thirukumaran
Thirukumaran

Reputation: 367

Circuit breaker Pattern

Is that fallback method and actual method should return same return type.

@HystrixCommand(fallbackMethod = "reliable")
  public String readingList() {
    URI uri = URI.create("http://localhost:8090/recommended");

    return this.restTemplate.getForObject(uri, String.class);
  }

  public String reliable() {
    return "Cloud Native Java (O'Reilly)";
  }

What I should do to return String from the fallback method reading list and return some Object from the actual method reliable?

Upvotes: 0

Views: 447

Answers (1)

pvpkiran
pvpkiran

Reputation: 27058

By definition fallback method means a substitution for real method if something were to happen.
You cannot return different type. It doesn't make any sense.
Hence method signature has to be exactly same with a few exceptions.

  1. Return types has to be same or covariant
  2. Method arguments has to be same. And you can add an extra argument of type Throwable to get the exception on which fallback was called.

Upvotes: 3

Related Questions