Skip to content

Use @FeignClient instead of ribbon-based restTemplate #7

@dgomesbr

Description

@dgomesbr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions