apolloconfig / apollo-use-cases

Show various usage scenarios and sample codes of the Apollo configuration center, welcome to share more configuration use cases in your daily work!
Apache License 2.0
944 stars 401 forks source link

add spring cloud gateway demo #26

Closed ksewen closed 5 years ago

ksewen commented 5 years ago

1、dynamic route config by apollo; 2、example how to dynamic delete route definition;

nobodyiam commented 5 years ago

Looks great, thanks!

However, I have a question regarding the following refresh logic:

private void refreshGatewayProperties(ConfigChangeEvent changeEvent) {
        logger.info("Refreshing GatewayProperties!");
        preDestroyGatewayProperties();
        this.applicationContext.publishEvent(new EnvironmentChangeEvent(changeEvent.changedKeys()));
        refreshGatewayRouteDefinition();
        logger.info("GatewayProperties refreshed!");
    }

After preDestroyGatewayProperties is executed and before refreshGatewayRouteDefinition is executed, what will happen if user access http://localhost:9090?

ksewen commented 5 years ago

in that time, the route has not be updated, if u follow the guide in README.md, u will route to https://githu.com. Spring listened EnvironmentChangeEvent to rebind the properties of bean with @ConfigurationProperties and Spring Cloud Gateway listened RefreshRoutesEvent to refresh routeDefinitions. u can see implements of RouteDefinitionLocator, in this case ,Spring Cloud Gateway will refresh the routes define in PropertiesRouteDefinitionLocator.