简体   繁体   English

如何在 spring 引导 Java 中动态获取假客户端名称和 url

[英]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.将来可能会有多个伪造服务,如 feignPaymentAbcService、feignPaymentxyz 服务等,因此根据服务,它应该获得伪造的客户端名称和正在运行服务的 url。 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)您可以使用 Feign 以及 Ribbon 和 Eureka 服务器来动态获取 url 以及服务器(或 url 列表,具体取决于实例)

@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.但名称必须存在,以便从 app.properties 文件中识别特定服务。 You need to add corresponding dependencies for eureka server & Ribbon Load balancer and you need to configure them in application.properties需要为eureka server & Ribbon Load balancer添加相应的依赖,需要在application.properties中配置

You can lookup my sample code here您可以在此处查找我的示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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