我正在尝试将服务实例注册到发现服务器并收到以下错误

问题描述 投票:0回答:1

我尝试向在 docker 上运行的 eureka 发现服务器注册我的微服务实例。该应用程序运行良好,但是当我尝试注册一个实例时,它会注册它,但会带来这个运行时异常...这是我的错误日志...我很困惑,因为它试图连接到 localhost:8761我没有在配置文件中配置。

2023-09-08 14:31:01 2023-09-08T13:31:01.536Z  INFO 1 --- [nio-9001-exec-2] c.n.e.registry.AbstractInstanceRegistry  : Registered instance API-GATEWAY/479d5ae21d41:api-gateway:9000 with status UP (replication=false)
2023-09-08 14:31:03 2023-09-08T13:31:03.618Z ERROR 1 --- [get_localhost-4] c.n.e.cluster.ReplicationTaskProcessor   : Network level connection to peer localhost; retrying after delay
2023-09-08 14:31:03 
2023-09-08 14:31:03 ***jakarta.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused***
2023-09-08 14:31:03     at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:439) ~[jersey-client-3.1.3.jar!/:na]
2023-09-08 14:31:03     at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:345) ~[jersey-client-3.1.3.jar!/:na]
2023-09-08 14:31:03     at com.netflix.eureka.transport.Jersey3ReplicationClient.submitBatchUpdates(Jersey3ReplicationClient.java:116) ~[eureka-core-jersey3-2.0.1.jar!/:2.0.1]
2023-09-08 14:31:03     at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:80) ~[eureka-core-2.0.1.jar!/:2.0.1]
2023-09-08 14:31:03     at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:190) ~[eureka-core-2.0.1.jar!/:2.0.1]
2023-09-08 14:31:03     at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2023-09-08 14:31:03 Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
2023-09-08 14:31:03     at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:03     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:13     at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2023-09-08 14:31:13 Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused
2023-09-08 14:31:13     at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:13     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:13     at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:13     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:13     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) ~org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) ~[httpclient-4.5.3.jar!/:4.5.3]
2023-09-08 14:31:23     at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:483) ~[jersey-apache-connector-3.1.3.jar!/:na
2023-09-08 14:31:23 
2023-09-08 14:31:26 2023-09-08T13:31:26.682Z  INFO 1 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 98ms
2023-09-08 14:31:33 2023-09-08T13:31:33.757Z ERROR 1 --- [et_localhost-16] c.n.e.cluster.ReplicationTaskProcessor   : Network level connection to peer localhost; retrying after delay
# Below is the application.yml file for the discovery server
server:
  port: 9001


spring:
  application:
    name: discovery-server


eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
  instance:
    hostname: localhost

#spring:
#  zipkin:
#    base-url: http://localhost:9411
#  sleuth:
#    sampler:
#      probability: 1.0

management:
  tracing:
    sampling:
      probability: 1.0
# Below is the docker compose configuration for discovery server
version: '3.8'

services:
  discovery-service:
    image:  discoveryservice
    container_name: discovery-service
    hostname: discovery-service
    environment:
      EUREKA_INSTANCE_HOSTNAME: discovery-service
    ports:
      - "9001:9001"
    networks:
      - grammercetamol
networks:
  grammercetamol:
    name: grammercetamol
    external: true

# Below is also the application.yml file for api-gateway, the instance i am trying to register to the server
server:
  port: 9000

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:9001/eureka
  instance:
    hostname: localhost


spring:
  application:
    name: api-gateway
    http:
      multipart:
        max-file-size: 50MB
        max-request-size: 40
  cloud:
    discovery:
      enabled: true
    gateway:
      routes:
#        Identity service route
        - id: identity-service
          predicates:
            - Path=/api/auth/**
          uri: lb://identity-service

#        Course service route
        - id: course-service
          predicates:
            - Path=/api/courses/**
          uri: lb://course-service

#          Video service route
        - id: video-service
          predicates:
            - Path=/api/videos/**
          uri: lb://video-service

#          cloudinary service route
        - id: cloudinary-service
          predicates:
            - Path=/api/cloudinary/**
          uri: lb://cloudinary-service
logging:
  level:
    root: INFO
    org:
      springframework:
        cloud:
          gateway: TRACE
          gateway.route.RouteDefinitionLoader: INFO
# The docker compose file for the instance API-GATEWAY
version: '3.8'

services:
  api-gateway:
    image: apigateway
    container_name: api-gateway
    ports:
      - "9000:9000"
    environment:
      EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://discovery-service:9001/eureka
      EUREKA_INSTANCE_HOSTNAME: api-gateway
#      - eureka_client_serviceUrl_defaultZone=http://discovery-server:9001/eureka
    networks:
      - grammercetamol
networks:
  grammercetamol:
    name: grammercetamol
    external: true
java spring-boot docker-compose docker-registry
1个回答
0
投票

您是否尝试过将

defaultZone
添加到
eureka.client
配置中?我的意思是这样的:

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka
  instance:
    hostname: localhost
© www.soinside.com 2019 - 2024. All rights reserved.