1

In our project we use Spring cloud + Eureka as service registry. When we use the ribbon client to call internal micro-services, all URL are resolved via Eureka ... that's a problem to call external URLs. As external API are old fashioned usage of Feign doesn't seem to be good choice.

What's the best way to call an external URL from such a service ?

Thanks in advance

Patrice

miken32
  • 42,008
  • 16
  • 111
  • 154
Patrice Conil
  • 83
  • 1
  • 8

2 Answers2

1

One way working: Use two configurations.

Declare your RestTemplate Bean to call external services like this:

@Primary
@Qualifier("withoutEureka")
@Bean
public RestTemplate restTemplate(){
...
}

Inject this reference in your client this way

@Bean
public MyClientForExtCall myClientForExtCall(@Qualifier("withoutEureka")RestTemplate restTemplate)

In the other configuration use the restTemplate as usual, but don't forget to use another qualifier

@LoadBalanced
@Bean
@Qualifier("withEureka")
public RestTemplate loadBalancedEureka(){
...
}

@Bean
public MyClientForInternal myClientForInternal(@Qualifier("withoutEureka")RestTemplate restTemplate)

Patrice

Patrice Conil
  • 83
  • 1
  • 8
0

You can use Ribbon without Eureka. For external APIs where you cannot configure in Eureka to abstract the discover. You can hard code their URLs in client and configure server list. The Ribbon client defaults to a configured server list, and you can supply the configuration like this:

stores:
  ribbon:
    listOfServers: example.com, google.com
madhu pathy
  • 429
  • 2
  • 6