我有3个组件-Eureka Server,货币兑换服务和货币换算服务。我已经将所有3个微服务都泊坞窗化了。当我使用docker engine(docker-compose.yml)运行这些容器时,它的工作正常。但是,当我将这些服务部署到AWS Beanstalk中时,就会出现问题。我可以看到服务能够注册到Eureka Server。我可以致电货币兑换服务并能够检索值。但是,当我呼叫依赖于货币兑换服务的货币转换服务时,通信失败。货币转换服务能够检索数据以从Eureka Server调用货币交换服务,但是当它调用货币交换服务时,它将获得未知的主机异常。有人可以帮忙吗? 以下是我的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]
答案 0 :(得分:0)
好的,因此我可以通过向所有向Eureka注册的微服务添加eureka.instance.preferIpAddress=true
来解决此问题。由于Docker容器ID充当系统无法解析的主机,因此发生了问题。