同一应用程序中的配置服务器和eureka服务器:尝试连接到localhost:8761

时间:2017-04-06 06:34:33

标签: spring-boot spring-cloud-netflix spring-cloud-config

我有一个spring-boot应用程序,用于在开发和测试环境中设置eureka serverlocalhost:8761。 奇怪的是,即使我将eureka.client.registerWithEureka设置为false,应用程序也会尝试连接到ERROR 3144 --- [et_localhost-12] c.n.e.cluster.ReplicationTaskProcessor : Network level connection to peer localhost; retrying after delay 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.4.10.jar:1.4.10] at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.4.10.jar:1.4.10] 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(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1] at com.sun.jersey.api.client.WebResource$Builder.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.4.10.jar:1.4.10] at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:71) ~[eureka-core-1.4.10.jar:1.4.10] at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.4.10.jar:1.4.10] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92] Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out

如何停用此功能?

错误:

@EnableEurekaServer
@EnableConfigServer
@SpringBootApplication
public class MyApplication {
  public static void main(String[] args) {
    SpringApplication.run(MyApplication.class, args);
  }
}

我唯一的课程看起来像这样:

application.yml

server: port: 8888 eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0 renewal-percent-threshold: 0.49 security: basic: enabled: true user: password: mypassword spring: jmx: default-domain: ${spring.application.name} cloud: config: server: git: uri: https://example.com/myrepo.git username: username password: password clone-on-start: true search-paths: '{application},{application}/{profile}' endpoints: jmx: domain: ${spring.application.name} unique-names: true

bootstrap.yml

1.1.6我只设置了应用程序名称。

版本:

spring-cloud-netflix-eureka:1.1.3, spring-cloud-config-server:Admin: Receive Statistics

5 个答案:

答案 0 :(得分:13)

您可以尝试更改配置,如下所示

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    service-url:
      defaultZone: http://localhost:8888/eureka

您指定server.port: 8888。所以你的eureka运行在8888端口上。但是您没有为eureka指定任何se​​rvice-url。所以我认为您的eureka服务器正在尝试复制到localhost:8761,因为它是默认的,并且您没有为eureka指定service-url。

答案 1 :(得分:4)

请使用您的Eureka服务器的8761端口,如下所示。

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

这里我们正在配置应用程序端口 - 8761是Eureka服务器的默认端口。我们告诉内置的Eureka客户端不要注册“本身”,因为我们的应用程序应该充当服务器。

答案 2 :(得分:2)

对我来说,下面对我有用的属性。

eureka.client.registerWithEureka= false
eureka.client.fetchRegistry= false
eureka.server.maxThreadsForPeerReplication=0

答案 3 :(得分:0)

如果您已自定义server.port属性,则必须在application.properties中添加属性eureka.client.service-url.defaultZone,因为eureka的默认端口为8761,并且defaultZone未指定,它将寻找与该端口的连接

server.port=8090

eureka.client.service-url.defaultZone=http://localhost:8090/eureka

答案 4 :(得分:0)

尽管进行了以下设置,但eureka似乎尝试连接到自身:

npm run build

您有两种选择来修复该问题:1-保留eureka的默认端口2-将以下内容添加到您的eureka服务器eureka.client.register-with-eureka=false eureka.client.fetch-registry=false 的{​​{1}}