feign使用问题, 请大神给指点下~~

liu_F_87 2019-03-24 05:59:40
我的应用场景是写一个对接设备主机的适配层,功能就是对接多个服务器主机的http协议接口;
多个服务器主机的协议接口内容相同,但是每个主机都有自己的ip地址
怎么才能动态改变feign注解里的 url访问地址呢;

设备主机只有httpserver用来接收处理消息, 没有微服务名;
而且也不需要负载均衡, 上层要给哪个设备发消息适配层就要能给指定的ip发送http请求


...全文
307 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu_F_87 2019-03-26
  • 打赏
  • 举报
回复
谢谢大家
liu_F_87 2019-03-26
  • 打赏
  • 举报
回复
找到个链接,里面有一些自定义的操作介绍 https://blog.csdn.net/u010862794/article/details/73649616


url动态指定如下:
interface GitHub {
// RequestLine注解声明请求方法和请求地址,可以允许有查询参数
@RequestLine("GET /repos/{owner}/{repo}/contributors")
List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}

static class Contributor {
String login;
int contributions;
}

public static void main(String... args) {
GitHub github = Feign.builder()
.decoder(new GsonDecoder())
.target(GitHub.class, "https://api.github.com");

// Fetch and print a list of the contributors to this library.
List<Contributor> contributors = github.contributors("OpenFeign", "feign");
for (Contributor contributor : contributors) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
}
bcsflilong 2019-03-25
  • 打赏
  • 举报
回复
用RestTemplate
qps2009 2019-03-25
  • 打赏
  • 举报
回复
就我个人目前所知道的,feign注解里的 url访问地址貌似不能动态改变,如果要调用其他的远程服务,可以用JDK原生的URLConnection、Apache的Http Client、Netty的异步HTTP Client, Spring的RestTemplate等来模拟http请求,通过改变url地址来访问不同地址的服务。

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧