使用Spring Cloud从微服务中获取外部IP

阿敏·阿布·塔莱布

我试图从我的一个微服务中获取外部服务。我将Spring Cloud,Eureka用于注册表,并将Spring Boot作为主要框架。

Map<String, String> urlVariables = new HashMap<>();
    urlVariables.put("ip_address", IP);
    urlVariables.put("port", PORT);

    ResponseObject state =
            restTemplate.getForObject("http://{ip_address}:{port}/state/", ResponseObject.class, urlVariables);

从我看到的情况来看,Spring Cloud将Ribbon注入为Rest模板的HTTP客户端,当我尝试点击该IP(例如193.172.x.x:)时,它会产生以下错误:

java.lang.IllegalStateException:org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor)上的193.172.xx实例在org.springframework.cloud.netflix.ribbon.RibbonClientHttpRequestFactory.createRequest(RibbonClientHttpRequestFactory.java:64)上不可用.java:76),位于org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:567),位于org.springframework.web.client.RestTemplate.execute(RestTemplate.java:540)。 client.RestTemplate.getForObject(RestTemplate.java:247)

似乎Ribbon尝试查找具有该名称的微服务实例,而不是在外部查找。有什么方法可以配置功能区以查找外部IP,还是仅用于内部使用?

马尔辛·格热兹扎克

您正在注入RestTemplate的@LoadBalanced版本。您必须确保RestTemplate是普通的香草模板。您可以使用创建它new RestTemplate()如果是Bean,只需添加一个限定符以确保您注入的是正确版本的RestTemplate

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Cloud微服务架构中的困惑

微服务系统中的 Spring Cloud 版本

部署Spring Cloud微服务时的IP地址规范

微服务不会从spring-cloud-config-server微服务获取属性

什么是OAuth2中使用spring cloud微服务的资源服务器

AWS中的Spring Cloud微服务部署

使用kubectl或kubernetes api获取服务的外部ip

Spring Boot从请求中获取承载令牌并调用另一个微服务

使用外部IP连接到在Cloud GCE VM上运行的Docker容器中的HTTPS服务器

带有Spring Boot的微服务,没有Spring Cloud

AWS Beanstalk中的Spring Boot微服务

Spring Cloud Gateway 可以与非异步的微服务一起使用吗?

使用Spring微服务从kubernetes集群中的服务中提取配置映射

如何在yml中获取我的配置值-使用dropwizard(微服务)Jersey DI @Injection?

带有密钥斗篷的Spring Cloud微服务

使用Spring Boot在微服务架构中管理会话的位置

使用Spring Boot微服务架构实现执行器

使用Config Server干净地部署Spring Boot微服务

使用Spring Security在入口点后面保护微服务

哪个是使用Spring的微服务的最佳API网关?

微服务无法在同一网络中使用 docker 获取 Spring Config Server 数据?

Spring Boot中微服务的安全性问题

Docker 中的 Spring Boot 微服务部署

在基于Spring Boot Webflux的微服务中,订户是谁?

在Spring Boot微服务中回滚liquibase的简便方法

是否可以使用任何npm或Google Cloud API从节点获取VM的外部IP地址?

使用Spring Security获取服务层中的登录用户

spring-cloud-sleuth中的三个微服务之一不显示spanid和添加依赖项后在日志中的令牌id

Kubernetes入口与使用外部IP的服务