Zuul not forwarding requests to other micro-services

无人久伴 提交于 2019-12-08 05:06:47

问题


I am using spring boot micro-services. I have configured eureka, zuul proxy and another microservice(account). If I am calling from account directly it is working fine. account and zuul server both showing on eureka.

When I try to hit using zuul proxy it is getting status code 200OK but not getting any result

Below is my configuration for 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: '*'

Console log so far

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

log of actuator/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": "*"
}

I am unable to get anything from here if something is mising, Kindly check and do let me know. any help will be useful

thanks.

If needed more info let me know.


回答1:


As I can see, you set up Eureka but you're not using it correctly. First in zuul yaml you have

eureka:
  client:
    registerWithEureka: true

you don't need to register your zuul application with eureka, because you are accessing zuul gateway directly, no one service will try to locate and reach your gateway.

Than

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

if you have service discovery you don't need url property and predicate: - Path, try:

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

by default serviceId is:

spring:
  application:
    name: <YOUR_ACCOUNT_SERVICE_ID>

check my answer from here



来源:https://stackoverflow.com/questions/55528763/zuul-not-forwarding-requests-to-other-micro-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!