简体   繁体   中英

how to get feign client name and url both dynamically in spring boot Java

I am new to feign client implementation, i have following code for current implementation.

FeignPaymentAbcService:
@FeignClient(name= "abc-service", url="abc url")
public interface FeignPaymentAbcService{

    //methods
}



 invoking call :
    (feignPaymentAbcService.someFunctionality("some input")).getBody();

In future there is possibility of multiple feign services like feignPaymentAbcService,feignPaymentxyz Service etc so according to service it should get feign client name and url in which service is running. Basically want to make in dynamic way.

Can anybody suggest any approach?

You can use the Feign along with Ribbon and Eureka server for dynamically getting the url along with the server( or list of urls depending on instances)

@FeignClient(name= "abc-service")
@RibbonClient(name = "abc-service")

but the name has to be there so that the particular service is identified from the app.properties file. You need to add corresponding dependencies for eureka server & Ribbon Load balancer and you need to configure them in application.properties

You can lookup my sample code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM