spring - spring RestTemplate 不解析尤里卡名称
问题描述
我有 1 个 eureka 服务器和 2 个微服务。它们称为 oauth 和身份验证。我启动了一切,两个微服务注册到尤里卡。我可以通过在浏览器中输入 eureka 服务器的 url 来验证这一点。
我现在想使用一个 resttemplate 以便 oauth 微服务可以与身份验证微服务进行通信。
在我的课堂上,我添加了这个自动接线
@Autowired
private RestTemplate restTemplate;
然后,我使用以下代码从 oauth 微服务与身份验证微服务进行通信。
ResponseEntity<ResponseDto<?>> responseEntity = restTemplate.exchange("http://authentication/api/authentication/verify",
HttpMethod.POST, request, typeRef);`
执行此代码时,我在日志中看到了这一点:
oauth | 2018-11-30 13:41:58.535 INFO 1 --- [nio-9001-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing SpringClientFactory-authentication: startup date [Fri Nov 30 13:41:58 GMT 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6743e411
oauth | 2018-11-30 13:41:58.641 INFO 1 --- [nio-9001-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
oauth | 2018-11-30 13:41:59.115 INFO 1 --- [nio-9001-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth | 2018-11-30 13:41:59.150 INFO 1 --- [nio-9001-exec-1] c.n.u.concurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-authentication
oauth | 2018-11-30 13:41:59.221 INFO 1 --- [nio-9001-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: authentication instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=authentication,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
oauth | 2018-11-30 13:41:59.237 INFO 1 --- [nio-9001-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater
oauth | 2018-11-30 13:41:59.303 INFO 1 --- [nio-9001-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth | 2018-11-30 13:41:59.310 INFO 1 --- [nio-9001-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client authentication initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=authentication,current list of Servers=[{MYSERVERSIP}:9003],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
oauth | },Server stats: [[Server:{MYSERVERSIP}:9003; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 00:00:00 GMT 1970; First connection made: Thu Jan 01 00:00:00 GMT 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
oauth | ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@1c33a40d
oauth | 2018-11-30 13:42:00.250 INFO 1 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: authentication.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
oauth | 2018-11-30 13:44:06.826 INFO 1 --- [nio-9001-exec-1] o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: InternalAuthenticationServiceException, I/O error on POST request for "http://authentication/api/authentication/verify": Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)
我可以从我的家用计算机访问身份验证微服务,这意味着端口是开放的。我已经尝试过 @LoadBalanced 注释,但是它不起作用。
到底是怎么回事?????
解决方案
我找到了解决方案。事实证明我有一个阻止请求的 iptables 规则。因此,如果您遇到这种情况,请检查您的 iptables 规则。
推荐阅读
- python - 如何获取 MongoDB 存储的视频文件的剪辑?
- sql - 在 oracle 中编辑请求(添加正确的左侧连接)
- javascript - 在 Vue.js 中调用 AJAX 后重新加载轮播
- excel - 过滤后vba计数可见行
- asp.net-mvc - 返回 RedirectToAction 不起作用
- vue.js - 奇怪的 VueJS 路由行为
- magento - Magento 1.9 - OroCRM 更新同步无法正常工作
- r - 非整数计数的泊松 GLM - R
- viewcontroller - 从另一个 VC 调用 var 的行代码是什么?
- github - 即使 PR 是针对另一个功能分支创建的,github 是否会将这个 PR 合并到“主”分支中?