Search code examples
javaspring-bootipcnetflix-eurekanetflix-zuul

Zuul not forwarding requests to other micro-services


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.


Solution

  • 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.

    Then

    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