我有两个服务:货币兑换和货币兑换我有一个 Eureka 服务器:命名服务器
在本地机器上,服务工作正常,我在另一个通常使用 eureka 服务器的服务方法上使用了一个服务方法,但是在 docker 上,它给了我一个白标错误 500:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback
There was an unexpected error (type=Internal Server Error status=500)
我在 eureka 服务器上使用 docker-compose,这两个服务显示正常(在每个服务的一个简单端点上,它也连接),当我尝试使用连接它们的端点时出现错误。
这是我的码头工人撰写:
version: '3.7'
services:
currency-exchange:
image: thiagoandradeit/microservicosin28minutes-currency-exchange-service:0.0.1-SNAPSHOT
mem_limit: 700m
ports:
- "8000:8000"
networks:
- currency-exchange
depends_on:
- naming-server
environment:
EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka
currency-conversion:
image: thiagoandradeit/microservicosin28minutes-currency-conversion-service:0.0.1-SNAPSHOT
mem_limit: 700m
ports:
- "8100:8100"
networks:
- currency-exchange
depends_on:
- naming-server
environment:
EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka
naming-server:
image: thiagoandradeit/microservicosin28minutes-naming-server:0.0.1-SNAPSHOT
mem_limit: 700m
ports:
- "8761:8761"
networks:
- currency-exchange
networks:
currency-exchange:
我的 openfeign 动态类:
@FeignClient(name="currency-exchange")
public interface CurrencyExchangeProxy {
@GetMapping("/currency-exchange/from/{from}/to/{to}")
public CurrencyConversion retrieveExchangeValue(@PathVariable String from,@PathVariable String to);
}
以下是我尝试通过货币兑换服务使用货币兑换时出现的部分日志:
currency-conversion_1 | 2021-03-15 18:59:33.696 WARN [currency-conversion,838d12e2c7e9960f,838d12e2c7e9960f] 1 --- [nio-8100-exec-6] .c.RetryAwareServiceInstanceListSupplier : No instances found after removing previously used service instance from the search ([EurekaServiceInstance@46ba90bd instance = InstanceInfo [instanceId = cc938ed0474f:currency-exchange:8000, appName = CURRENCY-EXCHANGE, hostName = localhost, status = UP, ipAddr = 172.19.0.6, port = 8000, securePort = 443, dataCenterInfo = com.netflix.appinfo.MyDataCenterInfo@46b93bf4]). Returning all found instances.
currency-conversion_1 | 2021-03-15 18:59:33.700 ERROR [currency-conversion,,] 1 --- [nio-8100-exec-6] 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: Connection refused (Connection refused) executing GET http://currency-exchange/currency-exchange/from/USD/to/INR] with root cause
currency-conversion_1 |
currency-conversion_1 | java.net.ConnectException: Connection refused (Connection refused)
currency-conversion_1 | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
currency-conversion_1 | at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.NetworkClient.doConnect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.http.HttpClient.(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.http.HttpClient.New(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.http.HttpClient.New(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) ~[na:na]
currency-conversion_1 | at java.base/java.net.HttpURLConnection.getResponseCode(Unknown Source) ~[na:na]
currency-conversion_1 | at feign.Client$Default.convertResponse(Client.java:108) ~[feign-core-10.10.1.jar:na]
currency-conversion_1 | at feign.Client$Default.execute(Client.java:104) ~[feign-core-10.10.1.jar:na]
currency-conversion_1 | at org.springframework.cloud.sleuth.instrument.web.client.feign.TracingFeignClient.execute(TracingFeignClient.java:79) ~[spring-cloud-sleuth-instrumentation-3.0.1.jar:3.0.1]
currency-conversion_1 | at org.springframework.cloud.sleuth.instrument.web.client.feign.LazyTracingFeignClient.execute(LazyTracingFeignClient.java:62) ~[spring-cloud-sleuth-instrumentation-3.0.1.jar:3.0.1]
currency-conversion_1 | at org.springframework.cloud.openfeign.loadbalancer.LoadBalancerUtils.executeWithLoadBalancerLifecycleProcessing(LoadBalancerUtils.java:56) ~[spring-cloud-openfeign-core-3.0.1.jar:3.0.1]
currency-conversion_1 | at org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient.lambda$execute$2(RetryableFeignBlockingLoadBalancerClient.java:156) ~[spring-cloud-openfeign-core-3.0.1.jar:3.0.1]
以下是我在 docker 上使用的一些 URL(在本地机器上,一切正常):
http://localhost:8000/currency-exchange/from/USD/to/INR (currency exchange only -
works fine with docker and eureka server)
http://localhost:8100/test (currency conversion only - works fine with docker and eureka server)
http://localhost:8100/currency-conversion-feign/from/USD/to/INR/quantity/10 (currency exchange consume currency conversion with openfeign - NOT WORKING with docker and eureka server, but works fine without docker)
我的货币兑换应用程序.properties
我的货币兑换应用程序.properties
spring.application.name=货币兑换 server.port=8000 spring.jpa.show-sql=true spring.datasource.url=jdbc:h2:mem:testdb spring.h2.console.enabled=true # 这个属性被 docker-compose 覆盖 eureka.client.service-url.defaultZone=http://localhost:8761/eureka #也许这个没有覆盖? eureka.instance.hostname=localhost
我的货币转换应用程序.properties
spring.application.name=货币转换 server.port=8100 #同货币兑换 eureka.client.service-url.defaultZone=http://localhost:8761/eureka eureka.instance.hostname=localhost
我的尤里卡服务器
spring.application.name=命名服务器 服务器端口=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false
我是 docker 和 spring-cloud 的新手。我认为他们没有找到彼此的名字,类似的东西。但我也在 docker-compose 上设置了 eureka URL。我不知道可以是什么。