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

Use @FeignClient instead of ribbon-based restTemplate #7

Open
dgomesbr opened this issue Sep 5, 2015 · 5 comments
Open

Use @FeignClient instead of ribbon-based restTemplate #7

dgomesbr opened this issue Sep 5, 2015 · 5 comments

Comments

@dgomesbr
Copy link

dgomesbr commented Sep 5, 2015

Hey guys, first of all thanks so much for the repo, amazing examples.
Second, I'm opening this issue to improve the usage of netflix-oss usage in the examples provided. Take for example the CommentsService.java

@HystrixCommand(fallbackMethod = "getFallbackCommentsForTask", commandProperties = {
            @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE"),
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
            @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "1000") })
    public CommentCollectionResource getCommentsForTask(String taskId) {
        // Get the comments for this task
        return restTemplate.getForObject(String.format("http://comments-webservice/comments/%s", taskId),
                CommentCollectionResource.class);

    }

Since it's just connecting to the comments-webservice could we just use the FeignClient?

@FeignClient(value = "http://comments-webservice", loadbalance = true)
interface CommentsClient{

    @RequestMapping(method = RequestMethod.GET, value = "http://comments-webservice/comments/{id}")
   CommentCollectionResource getCommentsForTask(@RequestParam("id") String taskId);
}

And in this case should we use Hystrix or not?

@manikandancvk
Copy link

Login Page is not redirecting to the login form .

Please refer the screenshots.
git_issue

@webjustin
Copy link

I hava the same issue as manikandancvk, do I miss any configuration?

@gabac
Copy link

gabac commented Nov 10, 2015

@manikandancvk @webjustin try it over the url http://localhost:8765/ as there is zuul running

@manikandancvk
Copy link

@gabac , Thanks for the reply , let me check the it out .

@anilallewar
Copy link
Contributor

@dgomesbr ,

Yes we could use FeignClient as declarative REST client instead of using RestTemplate. However we still need to provide fallback behaviour so that circuit breaker kicks in.

This is how I think you should be able to use FeignClient

  1. Add the feign-starter dependency to the gradle build
  2. Add the "fallback" attribute to the @FeignClient annotation which refers to a class
  3. The fallback class must implement the interface annotated by this annotation and be a valid spring bean. The easiest way to do this would be to have an static class that extends your base class (needs circuit breaker)

You can find more details at http://www.baeldung.com/spring-cloud-netflix-hystrix

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

No branches or pull requests

5 participants