Zuul不转发请求到其他微服务

2024-05-26

我正在使用 Spring Boot 微服务。我已经配置了 eureka、zuul 代理和另一个微服务(帐户)。如果我直接从帐户拨打电话,则工作正常。帐户和 zuul 服务器都显示在 eureka 上。

当我尝试使用 zuul 代理进行访问时,它会获取状态代码200OK但没有得到任何结果

以下是我的zuul配置

Zuul.yml

server:
  port: 8076
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8078/eureka/
  instance:
    hostname: localhost
    health-check-url-path: /actuator/health
    status-page-url-path: /actuator/info
logging:
  level:
    com.netflix.discovery: 'ON'
    org.springframework.cloud: DEBUG
zuul:
  ignoredServices: '*'
  routes:
    account:
      serviceId: ACCOUNT
      url: http://192.168.0.62:8081/
      stripPrefix: false
      predicate:
      - Path=/accounts/**
  debug:
    requests: true
management:
  security:
    enabled: false
  endpoints:
    web:
      exposure:
        include: '*'

到目前为止的控制台日志

路由匹配=ZuulRoute{id='account', path='/account/**', serviceId='账户', url='http://192.168.0.62:8081/ http://192.168.0.62:8081/', stripPrefix = false,可重试= null,sensitiveHeaders = [], 自定义敏感标头=假,} --------------------------- 映射到 org.springframework.cloud.netflix.zuul.web.ZuulController@7bb67520

执行器/env 的日志

"zuul.ignoredServices": {
"value": "*"
},
"zuul.routes.account.serviceId": {
"value": "ACCOUNT"
},
"zuul.routes.account.url": {
"value": "http://192.168.0.62:8081/"
},
"zuul.routes.account.stripPrefix": {
"value": false
},
"zuul.routes.account.predicate[0]": {
"value": "Path=/accounts/**"
},
"zuul.debug.requests": {
"value": true
},
"management.security.enabled": {
"value": false
},
"management.endpoints.web.exposure.include": {
"value": "*"
}

如果有东西丢失,我无法从这里得到任何东西,请检查并告诉我。任何帮助都会有用的

thanks.

如果需要更多信息,请告诉我。


正如我所看到的,您设置了尤里卡,但没有正确使用它。首先在 zuul yaml 中你有

eureka:
  client:
    registerWithEureka: true

您不需要向 eureka 注册您的 zuul 应用程序,因为您直接访问 zuul 网关,没有任何服务会尝试定位并访问您的网关。

Then

account:
  serviceId: ACCOUNT
  url: http://192.168.0.62:8081/
  stripPrefix: false
  predicate:
  - Path=/accounts/**

如果您有服务发现,则不需要url财产和predicate: - Path, try:

account:
  serviceId: <YOUR_ACCOUNT_SERVICE_ID>
  stripPrefix: false
  path: /account/**

默认情况下serviceId是:

spring:
  application:
    name: <YOUR_ACCOUNT_SERVICE_ID>

检查我的答案here https://stackoverflow.com/a/55616882/5953575

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Zuul不转发请求到其他微服务 的相关文章

随机推荐