本文主要是介绍spring cloud eureka报错8761 time out,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文链接:https://www.jianshu.com/p/788745f7dc7d
经常会使用Eureka Server作为注册中心,以下是我最近遇到的因为忽略了配置eureka.client.service-url.defaultZone而导致的异常,
com.sun.jersey.api.client.ClientHandlerException: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.8.7.jar:1.8.7]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.8.7.jar:1.8.7]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.access 200 ( W e b R e s o u r c e . j a v a : 74 ) [ j e r s e y − c l i e n t − 1.19.1. j a r : 1.19.1 ] a t c o m . s u n . j e r s e y . a p i . c l i e n t . W e b R e s o u r c e 200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1] at com.sun.jersey.api.client.WebResource 200(WebResource.java:74) [jersey−client−1.19.1.jar:1.19.1]atcom.sun.jersey.api.client.WebResourceBuilder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.8.7.jar:1.8.7]
at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-1.8.7.jar:1.8.7]
at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.8.7.jar:1.8.7]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.5.jar:4.5.5]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.5.jar:4.5.5]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
… 10 common frames omitted
从以上异常可以看到,服务一直在请求localhost:8761,而且始终超时,我检查了所有模块的注册中心地址配置,都没有发现8761这个端口,通过IDE全局搜索也没有找到这个端口,我启动的注册中心地址的端口为8000.
server.port=8000
eureka.instance.hostname=127.0.0.1
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
从网上查找,在https://www.jianshu.com/p/788745f7dc7d这篇文章里面有说明
package org.springframework.cloud.netflix.eureka;
import …
@ConfigurationProperties(“eureka.client”)
public class EurekaClientConfigBean implements EurekaClientConfig {
public static final String PREFIX = “eureka.client”;
public static final String DEFAULT_URL = “http://localhost:8761/eureka/”;
public static final String DEFAULT_ZONE = “defaultZone”;
private static final int MINUTES = 60;
@Autowired(
required = false
)
…
public EurekaClientConfigBean() {
this.serviceUrl.put(“defaultZone”, “http://localhost:8761/eureka/”);
this.gZipContent = true;
this.useDnsForFetchingServiceUrls = false;
this.registerWithEureka = true;
this.preferSameZoneEureka = true;
this.availabilityZones = new HashMap();
this.filterOnlyUpInstances = true;
this.fetchRegistry = true;
this.dollarReplacement = “_-”;
this.escapeCharReplacement = “__”;
this.allowRedirects = false;
this.onDemandUpdateStatusChange = true;
this.clientDataAccept = EurekaAccept.full.name();
this.shouldUnregisterOnShutdown = true;
this.shouldEnforceRegistrationAtInit = false;
}
…
}
问题得解,就是因为下面这行代码
public EurekaClientConfigBean() {
this.serviceUrl.put(“defaultZone”, “http://localhost:8761/eureka/”);
…
}
而我们的application.propertes中并没有配置defaultZone 。因此我们需要配置defaultZone 覆盖其默认值。完整application.propertes配置如下
server.port=8000
eureka.instance.hostname=127.0.0.1
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
##就是这个要覆盖,写成自己的地址
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
这篇关于spring cloud eureka报错8761 time out的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!