Search code examples
herokumicroservicesspring-cloudnetflix-eurekaspring-cloud-gateway

spring cloud gateway + eureka + microservice on heroku is putting the port in the url result is error 503 on request to microservice via gateway


I have 3 services deployed to Heroku.

  • Spring cloud Gateway
  • Eureka
  • a Microservice

The Gateway and the Microservice are registered in eureka.

GATEWAY application.yml

server:
  port: ${PORT:8080}

eureka:
  instance:
    hostname: gateway.herokuapp.com
    homePageUrl: https://${eureka.instance.hostName}/
  client:
    serviceUrl:
      defaultZone: http://eureka.herokuapp.com/eureka/
spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      routes:
        - id: employeeModule
          uri: lb://MICROSERVICE
          predicates:
            - Path=/employee/**
logging:
  level:
    org.springframework.cloud.gateway: TRACE

EUREKA application.yml

server:
  port: ${PORT:8761}

eureka:
  instance:
    hostname: ${EUREKA_HOSTNAME:localhost}
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: ${EUREKA_URI:http://${eureka.instance.hostname}:${server.port}/eureka/}

MICROSERVICE application.yml

spring:
  application:
    name: MICROSERVICE
server:
  port: ${PORT:8081}

eureka:
  instance:
    hostname: microservice.herokuapp.com
    homePageUrl: https://${eureka.instance.hostName}/
    home-page-url-path: https://${eureka.instance.hostName}
  client:
    serviceUrl:
      defaultZone: http://eureka.herokuapp.com/eureka/

I am getting the correct response, when i am calling directly https://MICROSERVICEURL/employee/message

when I am calling the gateway https://GATEWAYURL/employee/message it should ask eureka for the address of the microservice and then route the request to the microservice to get the response.

But instead of routing to https://MICROSERVICEURL/employee/message it routes to the eureka version with the random heroku port. e.g.: https://MICROSERVICEURL:RANDOMHEROKUPORT/employee/message. This leads to an error 503 because of a timeout.

Is there a way to tell the gateway to ignore the port number? Or am I doing something else wrong?

GATEWAY Log

2020-08-18T19:59:56.683925+00:00 app[web.1]: 2020-08-18 19:59:56.683 TRACE 4 --- [or-http-epoll-1] o.s.c.g.filter.LoadBalancerClientFilter  : LoadBalancerClientFilter url chosen: http://microservice.herokuapp.com:41632/employee/message
2020-08-18T20:00:26.673252+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/employee/message" host=gateway.herokuapp.com request_id=236faa79-1d66-4e30-8c32-f879228d08db fwd="79.205.56.29" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https


Solution

  • The solution was setting the secure and non secure port for the eureka instance in the appllication.yml

    MICROSERVICE application.yml

    spring:
      application:
        name: MICROSERVICE
    server:
      port: ${PORT:8081}
    
    eureka:
      instance:
        hostname: microservice.herokuapp.com
        homePageUrl: https://${eureka.instance.hostName}/
        home-page-url-path: https://${eureka.instance.hostName}
      client:
        serviceUrl:
          defaultZone: http://eureka.herokuapp.com/eureka/
          non-secure-port: 80
          secure-port: 443