Eureka-client 无法调用另一个 Eureka-client,抛出 UnknownHostException
Posted
技术标签:
【中文标题】Eureka-client 无法调用另一个 Eureka-client,抛出 UnknownHostException【英文标题】:Eureka-client not able to call another Eureka-client, throws UnknownHostException 【发布时间】:2019-07-04 22:14:24 【问题描述】:我有 3 个组件 - Eureka 服务器、货币兑换服务和货币兑换服务。我已经对所有 3 个微服务进行了 docker 化。当我使用 docker engine(docker-compose.yml) 运行这些容器时,它工作正常。但是当我将这些服务部署到 AWS Beanstalk 时,问题就出现了。我可以看到服务能够注册到 Eureka Server。我可以调用货币兑换服务并能够检索值。但是,当我调用依赖于货币兑换服务的货币兑换服务时,通信失败。 Currency Conversion Service 能够检索数据以从 Eureka Server 调用 Currency Exchange 服务,但是当它调用 Currency Exchange 服务时,它会收到未知的主机异常。有人可以帮忙吗? 以下是我的 Dockerrun.aws.json 详细信息 -
"AWSEBDockerrunVersion": 2,
"volumes": [
"name": "eureka-server",
"host":
"sourcePath": "/var/app/current/eureka-server"
,
"name": "currency-exchange-service",
"host":
"sourcePath": "/var/app/current/currency-exchange-service"
,
"name": "currency-conversion-service",
"host":
"sourcePath": "/var/app/current/currency-conversion-service"
,
"name": "nginx-proxy-conf",
"host":
"sourcePath": "/var/app/current/proxy/conf.d"
],
"containerDefinitions": [
"name": "eureka-server",
"image": "<name>/<tag_of_service>",
"essential": true,
"memoryReservation": 128,
"mountPoints": [
"sourceVolume": "eureka-server",
"containerPath": "/var/app"
],
"portMappings": [
"hostPort": 8761,
"containerPort": 8761
]
,
"name": "currency-exchange-service",
"image": "<name>/<tag_of_service>",
"essential": true,
"memoryReservation": 128,
"mountPoints": [
"sourceVolume": "currency-exchange-service",
"containerPath": "/var/app"
],
"portMappings": [
"hostPort": 8000,
"containerPort": 8000
],
"links": [
"eureka-server"
]
,
"name": "currency-conversion-service",
"image": "<name>/<tag_of_service>",
"essential": true,
"memoryReservation": 128,
"mountPoints": [
"sourceVolume": "currency-conversion-service",
"containerPath": "/var/app"
],
"portMappings": [
"hostPort": 8100,
"containerPort": 8100
],
"links": [
"eureka-server"
]
,
"name": "nginx-proxy",
"image": "nginx",
"essential": true,
"memoryReservation": 128,
"portMappings": [
"hostPort": 80,
"containerPort": 80
],
"links": [
"eureka-server", "currency-exchange-service", "currency-conversion-service"
],
"mountPoints": [
"sourceVolume": "nginx-proxy-conf",
"containerPath": "/etc/nginx/conf.d"
,
"sourceVolume": "awseb-logs-nginx-proxy",
"containerPath": "/var/log/nginx"
]
]
以下是例外-
2019-02-08 14:42:27.580 INFO 22 --- [nio-8100-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client currency-exchange-service initialized: DynamicServerListLoadBalancer:NFLoadBalancer:name=currency-exchange-service,current list of Servers=[bb0780eaed0b:8000],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;]
,Server stats: [[Server:bb0780eaed0b:8000; 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]
]ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@66d1ddb4
2019-02-08 14:42:27.868 ERROR 22 --- [nio-8100-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: bb0780eaed0b executing GET http://currency-exchange-service/currency-exchange/from/GBP/to/INR] with root cause
java.net.UnknownHostException: bb0780eaed0b
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[na:1.8.0_191]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_191]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_191]
at sun.net.NetworkClient.doConnect(NetworkClient.java:175) ~[na:1.8.0_191]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) ~[na:1.8.0_191]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) ~[na:1.8.0_191]
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242) ~[na:1.8.0_191]
at sun.net.www.http.HttpClient.New(HttpClient.java:339) ~[na:1.8.0_191]
at sun.net.www.http.HttpClient.New(HttpClient.java:357) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564) ~[na:1.8.0_191]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) ~[na:1.8.0_191]
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[na:1.8.0_191]
at feign.Client$Default.convertResponse(Client.java:143) ~[feign-core-10.1.0.jar!/:na]
at feign.Client$Default.execute(Client.java:68) ~[feign-core-10.1.0.jar!/:na]
at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:90) ~[spring-cloud-openfeign-core-2.1.0.RC3.jar!/:2.1.0.RC3]
at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:56) ~[spring-cloud-openfeign-core-2.1.0.RC3.jar!/:2.1.0.RC3]
at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:104) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:231) ~[rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:228) ~[rxjava-1.3.8.jar!/:1.3.8]
at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.drain(OnSubscribeConcatMap.java:286) ~[rxjava-1.3.8.jar!/:1.3.8]
at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.onNext(OnSubscribeConcatMap.java:144) ~[rxjava-1.3.8.jar!/:1.3.8]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:185) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.3.0.jar!/:2.3.0]
【问题讨论】:
【参考方案1】:好的,所以我可以通过将eureka.instance.preferIpAddress=true
添加到所有向 Eureka 注册自身的微服务来解决此问题。由于 docker 容器 id 充当系统无法解析的主机,因此出现问题。
【讨论】:
可以分享一下你是如何解决这个问题的吗?...谢谢以上是关于Eureka-client 无法调用另一个 Eureka-client,抛出 UnknownHostException的主要内容,如果未能解决你的问题,请参考以下文章
SpringCloud之Eureka-Client使用RestTemplate实现服务之间的调用
Eureka源码解析:eureka-client启动原理分析
SpringCloud之Eureka-Client服务提供者
SpringCloud之Eureka-Client实现服务(Jpa,H2)
Eureka-server配置servlet.context-path后导致Eureka-client注册到server问题