简体   繁体   中英

spring RestTemplate not resolving eureka names

I have 1 eureka server and 2 microservices. They are called oauth and authentication. I start up everything and the 2 microservices register to eureka. I can verify that by typing the url of the eureka server in my browser.

I now want to use a resttemplate so that oauth microservice can communicate with authentication microservice.

In my class I have added this autowired

@Autowired
private RestTemplate restTemplate;

I then use this following code to communicate from oauth microservice to the authentication microservice.

ResponseEntity<ResponseDto<?>> responseEntity = restTemplate.exchange("http://authentication/api/authentication/verify",
            HttpMethod.POST, request, typeRef);`

When this code is executed I see this in my logs:

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)

I can access the authentication microservice from my home computer so that means the port is open. I have tried the @LoadBalanced annotation however that doesn't work.

What is going on?????

I found the solution. It turns out I had an iptables rule that was blocking the request. So if this happens to you then check your iptables rules.

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