rohitghatol / spring-boot-microservices

Spring Boot Template for Micro services Architecture - Show cases how to use Zuul for API Gateway, Spring OAuth 2.0 as Auth Server, Multiple Resource (Web Services) Servers, Angular Web App, Eureka dor registration and Discover and Hystrix for circuit breaker
Apache License 2.0
1.77k stars 919 forks source link

Use @FeignClient instead of ribbon-based restTemplate #7

Open dgomesbr opened 9 years ago

dgomesbr commented 9 years ago

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 commented 9 years ago

Login Page is not redirecting to the login form .

Please refer the screenshots. git_issue

webjustin commented 9 years ago

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

gabac commented 9 years ago

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

manikandancvk commented 8 years ago

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

anilallewar commented 7 years ago

@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