1

Trying to use Feign Client with Eureka and Ribbon-

Have a service registered using Eureka with name-test-service.

Was able to use Ribbon and Eureka successfully as follows-

@Autowired
private LoadBalancerClient loadBalancer;

public void getEmployee() throws RestClientException, IOException {

    ServiceInstance serviceInstance=loadBalancer.choose("test-service");

    String baseUrl=serviceInstance.getUri().toString();

    baseUrl=baseUrl+"/test";

    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<String> response=null;
    try{
        response=restTemplate.exchange(baseUrl,
                HttpMethod.GET, getHeaders(),String.class);

        }

This works correctly including load balancing.

Now tried to replace RestTemplate with Feign as follows-

@FeignClient(name="test-service")
public interface RemoteCallService {
    @RequestMapping(method=RequestMethod.GET, value="/test")
    public String resp();

}

And making the call with feign as follows-

@Autowired
    private RemoteCallService loadBalancer;

    public void getEmployee() throws RestClientException, IOException {

        String data=loadBalancer.resp();

        }

But this is not working. The Feign URL is not getting formed correctly. On debugging the FeignClient has the following values-

HardCodedTarget(type=RemoteCallService, name=test-service, url=http://test-service)

Can anyone tell what am i missing.

Thanks

  • What are your dependencies? If you have `spring-cloud-starter-ribbon` it should auto configure feign to resolve the correct url. – spencergibb Jul 20 '17 at 15:00
  • Do have spring-cloud-starter-ribbon , spring-cloud-starter-eureka, spring-cloud-starter-feign dependencies. –  Jul 20 '17 at 16:17
  • You'll need to provide a sample that recreates the problem. – spencergibb Jul 20 '17 at 19:45

0 Answers0