Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds fallback implementation configuration to the HystrixFeign builder #308

Merged
merged 1 commit into from
Jan 7, 2016

Conversation

codefromthecrypt
Copy link
Contributor

Fallbacks are known values, which you return when there's an error invoking an http method.
For example, you can return a cached result as opposed to raising an error to the caller. To use
this feature, pass a safe implementation of your target interface as the last parameter to HystrixFeign.Builder.target.

Here's an example:

// When dealing with fallbacks, it is less tedious to keep interfaces small.
interface GitHub {
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  List<String> contributors(@Param("owner") String owner, @Param("repo") String repo);
}

// This instance will be invoked if there are errors of any kind.
GitHub fallback = (owner, repo) -> {
  if (owner.equals("Netflix") && repo.equals("feign")) {
    return Arrays.asList("stuarthendren"); // inspired this approach!
  } else {
    return Collections.emptyList();
  }
};

GitHub github = HystrixFeign.builder()
                            ...
                            .target(GitHub.class, "https://api.github.com", fallback);

Credit to the idea goes to @stuarthendren!

Fixes #298

@cloudbees-pull-request-builder

NetflixOSS » feign » feign-pull-requests #195 SUCCESS
This pull request looks good

@codefromthecrypt
Copy link
Contributor Author

ps @spencergibb at the level of abstraction of feign, it doesn't care how the fallback instance is created. so, it could be created by a dynamic proxy or whatever (which I suspect would be the way to integrate with custom annotation processing)

@codefromthecrypt codefromthecrypt changed the title Adds fallback implementation configuration to the HystrixFeign builder Adds fallback implementation configuration to the HystrixFeign builder Jan 6, 2016
@codefromthecrypt
Copy link
Contributor Author

will merge this in 8hrs unless there's blocking feedback, as there are folks waiting on 8.14

@codefromthecrypt
Copy link
Contributor Author

scrubbed covariants after seeing this! https://gist.github.com/JakeWharton/14547311b1f145cb0695

Fallbacks are known values, which you return when there's an error invoking an http method.
For example, you can return a cached result as opposed to raising an error to the caller. To use
this feature, pass a safe implementation of your target interface as the last parameter to `HystrixFeign.Builder.target`.

Here's an example:

```java
// When dealing with fallbacks, it is less tedious to keep interfaces small.
interface GitHub {
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  List<String> contributors(@param("owner") String owner, @param("repo") String repo);
}

// This instance will be invoked if there are errors of any kind.
GitHub fallback = (owner, repo) -> {
  if (owner.equals("Netflix") && repo.equals("feign")) {
    return Arrays.asList("stuarthendren"); // inspired this approach!
  } else {
    return Collections.emptyList();
  }
};

GitHub github = HystrixFeign.builder()
                            ...
                            .target(GitHub.class, "https://api.github.com", fallback);
```

Credit to the idea goes to @stuarthendren!
@cloudbees-pull-request-builder

NetflixOSS » feign » feign-pull-requests #198 SUCCESS
This pull request looks good

codefromthecrypt pushed a commit that referenced this pull request Jan 7, 2016
Adds fallback implementation configuration to the HystrixFeign builder
@codefromthecrypt codefromthecrypt merged commit 455525b into master Jan 7, 2016
@codefromthecrypt codefromthecrypt deleted the now-with-fallbacks branch January 7, 2016 09:04
@codefromthecrypt
Copy link
Contributor Author

this is now released as 8.14 cc @christopherlakey

velo pushed a commit that referenced this pull request Oct 8, 2024
Adds fallback implementation configuration to the HystrixFeign builder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants