【问题标题】:Spring Microservice not connecting to EurekaSpring 微服务未连接到 Eureka
【发布时间】:2019-01-23 15:27:38
【问题描述】:

我正在尝试将我的微服务与 Eureka 连接。

我在主类中添加了注解@EnableDiscoveryClient

@EnableDiscoveryClient
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

我在build.gradle 中使用下一个依赖项:

compile group: 'org.springframework.cloud', name: 'spring-cloud-netflix-eureka-client', version: '2.0.1.RELEASE'

最后,我添加了配置到application.yml

  eureka:
    client:
      serviceUrl:
        defaultZone: http://localhost:8761/eureka/
  spring:
    application.name: receipt-processing-microservice  

而且,正如您所建议的那样,它不起作用。我的日志我没有看到任何带有标签DiscoveryChannelEureka 的日志

【问题讨论】:

  • 你连接eureka查看服务列表了吗? localhost:8761/#
  • 是的,服务不在注册服务列表中。
  • 您没有收到任何错误或异常?如果您没有收到错误并且您没有看到它注册......我猜您的配置可能有问题。也许您的 eureka 客户端代码永远不会运行……例如,您有 @EnableDiscoveryClient 吗?您使用的是哪个指南?我看了piotrminkowski.wordpress.com/2018/04/26/…
  • 是的,我没有看到任何错误或异常。我什至尝试将错误的defaultZone uri 设置为 erureka,但日志、错误或异常中仍然没有信息。我尝试添加@EnableDiscoveryClient@EnableEurekaClient,它们都没有帮助。似乎确实,尤里卡代码永远不会运行,但我不明白为什么!我用过好几个指南,第一个来自spring.io/guides/gs/service-registration-and-discovery
  • 我在 build.gradle 中更新了 Spring Boot 版本后问题得到了修复。

标签: java spring netflix-eureka


【解决方案1】:

也许您缺少部分配置?

我有以下一切,一切正常:

#Eureka configuration
eureka.client.enabled=true
eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICE_URL:http://admin:admin@localhost:7995}/eureka/
eureka.client.healthcheck.enabled=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.instance.leaseRenewalIntervalInSeconds=15
eureka.instance.leaseExpirationDurationInSeconds=30

您可以尝试使用更多参数,看看会发生什么。

另外,请检查 eureka web-ui 中的服务列表,以防它只是控制台日志问题:请参阅 localhost:8761/# 。

【讨论】:

  • 我已经添加了您列出的所有参数,但没有帮助。
  • 检查 localhost:8761/# 太明显了,我没有写。 Eureka 控制台也没有关于我的服务的任何信息。
【解决方案2】:

尝试启用调试日志。您将获得大量信息(您可以将其重定向到文件)并尝试查看下面发生的情况——尤其是在容器启动之后和发现客户端被初始化时。在我的情况下,发现服务器在 8061 端口上运行,我的服务注册日志如下所示(请参阅指示服务向尤里卡服务器发送注册请求的日志)

DEBUG [employee-service,,,] Returning cached instance of singleton bean 'refreshEventListener'
 DEBUG [employee-service,,,] Closing connections idle longer than 30000 SECONDS
 DEBUG [employee-service,,,] Closing connections idle longer than 30000 SECONDS
  INFO [employee-service,,,] Disable delta property : false
  INFO [employee-service,,,] Single vip registry refresh property : null
  INFO [employee-service,,,] Force full registry fetch : false
  INFO [employee-service,,,] Application is null : false
  INFO [employee-service,,,] Registered Applications size is zero : true
  INFO [employee-service,,,] Application version is -1: false
  INFO [employee-service,,,] Getting all instance registry info from the eureka server
  Get connection: {}->http://localhost:8061, timeout = 5000
  [{}->http://localhost:8061] total kept alive: 1, total issued: 0, total allocated: 1 out of 200
  Getting free connection [{}->http://localhost:8061][null]
  Stale connection check
  CookieSpec selected: default
  Auth cache not set in the context
  Target auth state: UNCHALLENGED
  Proxy auth state: UNCHALLENGED
  Attempt 1 to execute request
  Sending request: GET /eureka/apps/ HTTP/1.1
   >> "GET /eureka/apps/ HTTP/1.1[\r][\n]"
   >> "Accept: application/json[\r][\n]"
   >> "DiscoveryIdentity-Name: DefaultClient[\r][\n]"
   >> "DiscoveryIdentity-Version: 1.4[\r][\n]"
   >> "DiscoveryIdentity-Id: 192.168.28.145[\r][\n]"
   >> "Accept-Encoding: gzip[\r][\n]"
   >> "Host: localhost:8061[\r][\n]"
   >> "Connection: Keep-Alive[\r][\n]"
   >> "User-Agent: Java-EurekaClient/v1.9.2[\r][\n]"
   >> "[\r][\n]"
  >> GET /eureka/apps/ HTTP/1.1
  >> Accept: application/json
  >> DiscoveryIdentity-Name: DefaultClient
  >> DiscoveryIdentity-Version: 1.4
  >> DiscoveryIdentity-Id: 192.168.28.145
  >> Accept-Encoding: gzip
  >> Host: localhost:8061
  >> Connection: Keep-Alive
  >> User-Agent: Java-EurekaClient/v1.9.2
  Get connection: {}->http://localhost:8061, timeout = 5000
  [{}->http://localhost:8061] total kept alive: 0, total issued: 1, total allocated: 1 out of 200
  No free connections [{}->http://localhost:8061][null]
  Available capacity: 49 out of 50 [{}->http://localhost:8061][null]
  Creating new connection [{}->http://localhost:8061]
   << "HTTP/1.1 200 [\r][\n]"
   << "Content-Encoding: gzip[\r][\n]"
   << "Content-Type: application/json[\r][\n]"
   << "Content-Length: 549[\r][\n]"
   << "Date: Tue, 28 Aug 2018 06:48:14 GMT[\r][\n]"
   << "[\r][\n]"
  Receiving response: HTTP/1.1 200 
  << HTTP/1.1 200 
  << Content-Encoding: gzip
  << Content-Type: application/json
  << Content-Length: 549
  << Date: Tue, 28 Aug 2018 06:48:14 GMT
  Connection can be kept alive indefinitely
   << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x9d]S[0xd1][0x8e][0xda]0[0x10][0xfc][0x17][0xeb][0x1e]![0x10][0x8]4[0x97][0xa7];[0x91][0xa8][0x8a][0xda][0x3]D[0xca]UUU![0xd7]Y[0x88]U[0xc7][0x8e]l[0x87]k[0x84][0xf8][0xf7][0xae][0x93][0x86][0x96]SQ[0xd5]*[0xf][0x89]wg[0xd7];3[0x9b][0x13][0xa1]U%8[0xa3][0x96]+iHt"G[0xd0][0xc6]}[0xef]v9[0x8]KID|2p([0x8c][0x14][0xd4][0x14]L[0xe5][0x80][0xc1][0xed]z[0xe7][0xef][0xba]D_N[0xa2][0xcf]'"i[0xe9][0xd2][0xc9][0xd3][0xfa][0xfd][0xea]S[0x92][0xc][0xb3]d[0xf3][0x9c].[0x12]Dri,[0x95][0xc]ZXHs[0x4][0xa7][0x9b]4[0x1b].[0xb2][0xb7]C6[0xe3][0x95][0xa6]P%x[0x12]l[0x4]e%T[0x3]04[0xa0][0x8f][0x9c]A[0x14][0x8e][0xef][0xc7][0xd8][0xaa]P[0xc6].[0xbb][0x8b]n[0xd5]v[0xa3][0xdd][0x98][0xa4]z[0xcc]s[0xed][0x98][0xdd]O<[0x1e]z[0x93][0xd0][0xf3][0x83][0x19]fp([[0x9b][0x96][0x1e][0x9e][0x14]j[0xa1]y[0x9e][0x83][0xcc].[0xf1][0xe5][0xbb][0xe5][0xea][0xe3][0x12][0x93][0x95][0xd2][0xd6][0xe9]uG[0xda][0xa9][0x6][0xe4][0x1]$[0xfd]*[0xc0][0x11][0xb2][0xba][0x6]r[0xc6]v[0xc0]j[\r][0xeb]_[0xc8] [0x98]^[0x1][0xf7]T[0x98][0x16][0xc9]T-[0xad]n[0x9c][0x1c][0xfe][0x80][0xe4][0xd4][0xd2][0x5]H[0xb]:[0x95]{[0xe5]j[0x1f][0x98][0xa0][0xc6][\r][0xc0]T[0xe9][0xe8][0xed][0x5][0xff][0xee]!A[0x8e]y/[0xed][0xc5][0xc4][0xc3]][0xc]{Z[0xb][0x1b]_[0xb7][0x18][0xf4][0xc6]<5[0xab][0x17][0xe9]n[0x14]@[\r][0xf4][0xed]5Hx[0xa1]"u[0xf8][0xa3]{g[0xc0][0xf0][0xb6])[0xd2][0xca]k[0xdd][0xba][0xdb][0xc7][0x1c]U[\r][0x7]nl[0x17][0xff][0xc0]K[0xc0][0xeb]K[0xd4][0xda][0x9f]Mg[0xc1]4[0xc][0xe7][0xc1][0xc4][0xf][0xf1][0x6]j[0xec][0xa6]k|[0x1b][0x4][0xe8][0xeb][0xab]6c'\[0xeb][0xf7][0xb6][0xba]U[0x88][0x4]J[0xb0][0xd4][0x9][0xe5][0xe6]/[0xa9][0xa4][0x7]([0x91][0xaf][0xd7][0xf9]B[0xda]M9[0xbb]U)a[0x8d][0xb9][0xad][0x16][0x18]-[0xac][0xad][0xa2][0xd1][0xe8][0xe6][0xc2][0xb9][0xaa][0xd1]e[0xf][0xfe][0xb1][0x8e]2[S[0xab][0xf4][0x88]w[0x8a][0x17]@[0x85]-[0x16][0x5][0xb0]o[0xff][0xd3][0xa5]+[0xc7]>[0xc7]n_[0xa1][0xf5][0xff][0xf5]/A[0xfa]-{[0xfe][0xb][0x8a][0x9b][0x85]R:[0xe7][0x12]][0x93][0x87][0x98][0x1b][0xe6][0xd6][0xbb][0xc9][0x10][0x0][0xfa][0xb2][0x8a][0x9d]k[0xdb][\n]"
   << "[0x85][0x85][0xfc]7[0xf1][0xc9][0x95][0xfa]?a1[0xd7][0xb6][0xf9]3h<[\r][0xdc][0x1f][0xd8]Y[0xdb]Tn[0xf3][0x1e][0xe3]8[0x89][0xc9][0xf9][0xb]>[0xe7][0x1f][0xc1][0x8d][0x8f][0xd8]w[0x4][0x0][0x0]"
  Connecting to localhost:8061
  CookieSpec selected: default
  Auth cache not set in the context
  Target auth state: UNCHALLENGED
  Proxy auth state: UNCHALLENGED
  Attempt 1 to execute request
  Sending request: PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1
   >> "PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1[\r][\n]"
   >> "DiscoveryIdentity-Name: DefaultClient[\r][\n]"
   >> "DiscoveryIdentity-Version: 1.4[\r][\n]"
   >> "DiscoveryIdentity-Id: 192.168.28.145[\r][\n]"
   >> "Accept-Encoding: gzip[\r][\n]"
   >> "Content-Length: 0[\r][\n]"
   >> "Host: localhost:8061[\r][\n]"
   >> "Connection: Keep-Alive[\r][\n]"
   >> "User-Agent: Java-EurekaClient/v1.9.2[\r][\n]"
   >> "[\r][\n]"
  >> PUT /eureka/apps/EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090?status=UP&lastDirtyTimestamp=1535438864034 HTTP/1.1
  >> DiscoveryIdentity-Name: DefaultClient
  >> DiscoveryIdentity-Version: 1.4
  >> DiscoveryIdentity-Id: 192.168.28.145
  >> Accept-Encoding: gzip
  >> Content-Length: 0
  >> Host: localhost:8061
  >> Connection: Keep-Alive
  >> User-Agent: Java-EurekaClient/v1.9.2
   << "HTTP/1.1 200 [\r][\n]"
   << "Content-Type: application/xml[\r][\n]"
   << "Content-Length: 0[\r][\n]"
   << "Date: Tue, 28 Aug 2018 06:48:14 GMT[\r][\n]"
   << "[\r][\n]"
  Receiving response: HTTP/1.1 200 
  << HTTP/1.1 200 
  << Content-Type: application/xml
  << Content-Length: 0
  << Date: Tue, 28 Aug 2018 06:48:14 GMT
  Connection can be kept alive indefinitely
  Released connection is reusable.
  Releasing connection [{}->http://localhost:8061][null]
  Pooling connection [{}->http://localhost:8061][null]; keep alive indefinitely
  Notifying no-one, there are no waiting threads
  Jersey HTTP PUT http://localhost:8061/eureka//apps/EMPLOYEE-SERVICE/aaa-aaa-1567.mshome.net:employee-service:8090; statusCode=200
  DiscoveryClient_EMPLOYEE-SERVICE/aaaa-aaa-1567.mshome.net:employee-service:8090 - Heartbeat status: 200

【讨论】:

    【解决方案3】:

    在 application.yml 文件中将配置服务器端口更改为 8888。

    server:
      port: 8888
    

    【讨论】:

      猜你喜欢
      • 2019-10-11
      • 2020-05-22
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2021-09-20
      相关资源
      最近更新 更多