Spring Eureka 客户端注册上的未知端口问题

Problem with unknown ports on Spring Eureka Client registration

好吧,我已经尝试了所有教程,所有关于 Whosebug 的答案。但我仍然面临同样的错误:

在 Heroku 上,Eureka 客户端正在接收我不知道它们来自何处的随机端口。

并且这些随机端口与 Heroku 环境变量 $PORT 不同。我知道 $PORT 是容器 Dyno 端口,而不是外部世界可以访问的主机端口 xxxxx.herokuapp.com。再一次,我不知道这些端口来自哪里!!!

Eureka 仪表板中的 link 个客户端保持这样:

hdfb2324-8jfw-83ud-dkdf-9ej90jefj201.qwer.dyno.rt.heroku.com:inight-ws-gateway:${RANDOM PORT}

当我点击时,转到 https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info。我采用超时,因为正确的端口是 443,默认为 Https。

我有 3 个应用程序,1 个 Eureka 服务器和 2 个 Eureka 客户端(Zuul 网关和一个普通的 Rest API)。

当我在我的本地主机上 运行 时一切正常,但是当我在 Heroku 中部署时,它发生了。

尤里卡服务器application.yaml:

server:
  port: ${PORT} 

spring:
  application:
    name: '@project.artifactId@' # inight-ws-discovery
    version: '@project.version@'

eureka:
  client:
    fetch-registry: false
    register-with-eureka: false

management:
  endpoints:
    enabled-by-default: false
    web:
      exposure:
        include:
        - health
        - info
  endpoint:
    health:
      enabled: true
    info:
      enabled: true

Eureka客户端(Zuul网关)application.yaml:

server:
  port: ${PORT}

spring:
  application:
    name: '@project.artifactId@' # inight-ws-gateway
    version: '@project.version@'

eureka:
  instance:
    hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} # inight-ws-gateway.herokuapp.com
  client:
    enabled: true
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} # https://inight-ws-discovery.herokuapp.com/eureka/
    healthcheck:
      enabled: true

zuul:
  sensitive-headers:
  - Cookie

management:
  endpoints:
    enabled-by-default: false
    web:
      exposure:
        include:
        - health
        - info
        - routes
  endpoint:
    health:
      enabled: true
    info:
      enabled: true
    routes:
      enabled: true

jwt:
  config:
    privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}

尤里卡客户端(休息API)application.yaml:

server:
  port: ${PORT}

spring:
  application:
    name: '@project.artifactId@' # inight-ws-auth
    version: '@project.version@'
  datasource:
    hikari:
      schema: inight
      jdbc-url: ${INIGHT_DATASOURCE_JDBC_URL}
      username: ${INIGHT_DATASOURCE_USERNAME}
      password: ${INIGHT_DATASOURCE_PASSWORD}
      driver-class-name: ${INIGHT_DATASOURCE_DRIVER_CLASS_NAME}
  jpa:
    show-sql: ${INIGHT_JPA_SHOW_SQL}
    hibernate:
      ddl-auto: ${INIGHT_JPA_HIBERNATE_DDL_AUTO}

eureka:
  instance:
    hostname: ${INIGHT_EUREKA_INSTANCE_HOSTNAME} inight-ws-auth.herokuapp.com
  client:
    enabled: true
    service-url:
      defaultZone: ${INIGHT_EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE} https://inight-ws-discovery.herokuapp.com/eureka/
    healthcheck:
      enabled: true

management:
  endpoints:
    enabled-by-default: false
    web:
      exposure:
        include:
        - health
        - info
  endpoint:
    health:
      enabled: true
    info:
      enabled: true

jwt:
  config:
    privateKey: ${INIGHT_JWT_CONFIG_PRIVATEKEY}

swagger.basePackage: br.com.bz.inight.auth.controller

When I click, go to https://inight-ws-gateway.herokuapp.com:${RANDOM PORT}/actuator/info. I take the Timeout because the correct port is 443, Https default.

当您在本地主机上托管时,link 将是:http://localhost:${PORT}/actuator/info

在 Heroku 上,这个 link 是:https://inight-ws-gateway.herokuapp.com/actuator/info

区别:

  • 正在使用 http secure、https
  • 端口号是"gone"

主机名 inight-ws-gateway.herokuapp.com 自动翻译成 ${IP_ADDRESS}:${PORT}

您需要为 https URL 生成调整您的源代码。


您的 Web 应用程序将 运行 使用与通常 http/https 端口不同的端口。它不必是 80、8080 或 443。它可以是任何端口。该端口由 Heroku 通过 $PORT.

指定

我的错!!!! 我在 Heroku 上有几个微服务:

  • 尤里卡服务器
  • Zuul 网关
  • 部分应用服务

Eureka Server Dashboard 上的link,无所谓。重要的是 https://GATEWAY.herokuapp.com/actuator/routes and the <port enabled="true">80</port> on https://EUREKA_SERVER.herokuapp.com/eureka/apps.

但要发生这种情况(<port enabled="true">80</port> 在应用服务上)您必须明确,在application.yaml

中声明
eureka:
  instance:
    non-secure-port: 80
    hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com

如果你阅读文档,你会看到 属性 eureka.instance.non-secure-port 有默认值 80。我不知道为什么,但是,如果你不声明它, <port enabled="true">80</port> 未在 Eureka Server 上的微服务应用程序上设置。

查看教程https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka

嗯,这些是我的架构application.yaml:

coffee-eureka-server application.yaml

spring:
  application:
    name: '@project.artifactId@'

server:
  port: ${PORT}

eureka:
  instance:
    hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: ${EUREKA_SERVER_URI}/eureka/ # in this case, same value of eureka.instance.hostname, but with https:// prefix, of course

coffee-zuul-gateway application.yaml

spring:
  application:
    name: '@project.artifactId@'

server:
  port: ${PORT}

eureka:
  instance:
    hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: ${EUREKA_SERVER_URI}/eureka/

management:
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include:
        - routes
        - info
        - health

coffee-simple-ms application.yaml

spring:
  application:
    name: '@project.artifactId@'

server:
  port: ${PORT}

eureka:
  instance:
    non-secure-port: 80 # <<<<<<<<< HERE
    hostname: ${EUREKA_CLIENT_INSTANCE_HOSTNAME} # herokuapp_name.herokuapp.com
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: ${EUREKA_SERVER_URI}/eureka/