Eureka Ribbon LoadBalancer Cache update delay

孤街醉人 提交于 2019-12-24 00:38:52

问题


I am setting up a micro service based application, where Aggregation layer / API gateway makes calls to micro services. Eureka is used for service discovery and Ribbon for providing a load balancing RestTemplate.

Postman calls Aggregation--> Aggregation calls Micro service using Eureka/Ribbon/RestTemplate.

I have 4 instances of one micro services type running on my machine on 4 different ports. Hitting the same REST endpoint repeatedly Postman causes the requests to get load balanced properly in a round robin fashion.

When I stop one of the micro service instances the service is deregistered from Eureka, but the LoadBalancer still sends requests to the dead service and the call fails.

Below is my code:

Aggregation:

 @Configuration
    @ComponentScan(basePackages = {"com.mycompany.aggregator"})
    @EnableAutoConfiguration
    @EnableEurekaClient
    public class AggregatorApplication {

        public static void main(String[] args) {
            SpringApplication.run(AggregatorApplication.class, args);
        }
    }

**Configuration:**
@Configuration
public class AggregatorConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

@Configuration
@RibbonClient(name="microservice", configuration = FooConfig.class)
public class TestConfig {
}

//FooConfig is excluded from component-scan

@Configuration
public class FooConfig {

    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new NIWSDiscoveryPing();
    }

    @Bean
    public IRule ribbonRule(IClientConfig config) {
        return new AvailabilityFilteringRule();
    }
}

restTemplate call:

ResponseEntity<Object> responseEntity = restTemplate.getForEntity(myUrl, Object.class);

Properties:

spring.application.name=aggregator
server.contextPath=/ott
server.port = 8090
my.url=http://microservice
eureka.instance.leaseRenewalIntervalInSeconds=1
eureka.instance.leaseExpirationDurationInSeconds=2

MicroService Code:

@SpringBootApplication
@EnableEurekaClient
public class MicroServiceApplication

Properties:

spring.application.name=microservice
server.contextPath=/ott
server.port = 9000
eureka.instance.leaseRenewalIntervalInSeconds=1
eureka.instance.leaseExpirationDurationInSeconds=2

Eureka Server:

@SpringBootApplication
@EnableEurekaServer
public class EurekaserverApplication {

Properties:

server.port=8761

eureka.server.enableSelfPreservation=false
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF

回答1:


The issue causing this is that Eureka intellisense gives the shutdown instance more time to come up. The intellisense works this way for multiple microservices with the same name running on the same box.

When the services are deployed on different boxes then this issue doesn't come up.



来源:https://stackoverflow.com/questions/42265210/eureka-ribbon-loadbalancer-cache-update-delay

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