小编典典

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

spring-boot

我正在使用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: '*'

到目前为止的控制台日志

route match = ZuulRoute {id =’account’,path =’/ account / **’,serviceId
=’ACCOUNT’,url =’ http://192.168.0.62
:8081/’,stripPrefix = false,retryable = null, sensitiveHeaders =
[],customSensitiveHeaders = false,}
---------------------------映射到org.springframework.cloud.netflix.zuul.web
.ZuulController @ 7bb67520

执行器/环境日志

"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": "*"
}

如果发生问题,我无法从这里得到任何东西,请检查并告知我。任何帮助都会有用

谢谢。

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


阅读 1493

收藏
2020-05-30

共1个答案

小编典典

如我所见,您设置了Eureka,但使用不正确。首先在zuul yaml中

eureka:
  client:
    registerWithEureka: true

您不需要在eureka上注册zuul应用程序,因为您是直接访问zuul网关,因此没有任何服务会尝试找到并访问您的网关。

然后

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

如果您有服务发现,则不需要url属性和predicate: - Path,请尝试:

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

默认情况下,serviceId为:

spring:
  application:
    name: <YOUR_ACCOUNT_SERVICE_ID>
2020-05-30