1

I have the following services

Service A - Sends request to service B using RestTemplate.

Service B - Has an end point that returns "Hello Universe".

Service G - "Spring Cloud Gateway".

Service A sends request to Service B using API Gateway URL using REST Template.

But, how does it work with Feign Client? For example below is the FeignClient of Service B in Service A

@FeignClient(name = "serviceb")
public interface ServiceBClient {
    @GetMapping("/getmessage/")
    public Inventory getInventoryDetails();
}

I believe one of the primary reasons we use a gateway is to allow the service A to send request to Gateway instead of directly using the service name.

But it seems with feign client the purpose is destroyed.

How to send request to Gateway using feign client?

rakesh mehra
  • 618
  • 1
  • 9
  • 21
  • the `name` attribute would need to be the serviceId of the gateway. – spencergibb Sep 15 '20 at 16:31
  • Couple of pointers. 1) You will have name conflict if you have more than two FeignClients and they all have same name 2) With feign client, we are copying the method signatures. Wouldn't this destroy the purpose of gateway, as the client still needs to do some work pertaining to a specific service? – rakesh mehra Sep 15 '20 at 16:58

1 Answers1

0

if you want to give the URL of API-gateway, you can provide it instead of the service name. then the request doesn't go to the related service and, the request goes to the API gateway and, the API gateway will route the request to the relevant service. then the API gateway will be busy for nothing. because, if you gave the service name, the request directly goes to the request by using the cached services IP address data. due to the internal request, the request doesn't want to go through the security filters as well.

@FeignClient(url = "http://localhost:8081/order-service")
Mafei
  • 3,063
  • 2
  • 15
  • 37