Home > Enterprise >  Is there any way for API Gateway to find the User service immediately?
Is there any way for API Gateway to find the User service immediately?

Time:10-17

I'm having a problem with Eureka. I have 3 components:

  • Eureka (port 8761)
  • User service (port 3001)
  • API Gateway (port 2001)
@Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                // User service
                .route(r -> r.path("/user-service/**")
                        .filters(f -> f.rewritePath("/user-service/", "/").dedupeResponseHeader(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeader.RETAIN_UNIQUE))
                        .uri("lb://USER-SERVICE"))

                .build();
    }

I start Eureka and API Gateway first, then start User service. I access the user service through API Gateway (http://localhost:2001/user-service) but error "Unable to find instance for USER-SERVICE" is display, and a few seconds later, it works.

error message

Is there any way for API Gateway to find the User service immediately?

CodePudding user response:

You can change the property indicating how often(in seconds) to fetch the registry information from the eureka server. The default value is 30s as can be found on the link.

eureka.client.registry-fetch-interval-seconds=30s
  • Related