Procházet zdrojové kódy

Upgrade apollo-client to 1.3.0 and add support for removing listener in sentinel-datasource-apollo (#562)

- Add to unsubscribe config change event
master
Neptune Eric Zhao před 5 roky
rodič
revize
7367da6936
2 změnil soubory, kde provedl 8 přidání a 4 odebrání
  1. +1
    -1
      sentinel-extension/sentinel-datasource-apollo/pom.xml
  2. +7
    -3
      sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java

+ 1
- 1
sentinel-extension/sentinel-datasource-apollo/pom.xml Zobrazit soubor

@@ -12,7 +12,7 @@
<artifactId>sentinel-datasource-apollo</artifactId>

<properties>
<apollo.version>1.0.0</apollo.version>
<apollo.version>1.3.0</apollo.version>
</properties>

<dependencies>


+ 7
- 3
sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java Zobrazit soubor

@@ -20,6 +20,7 @@ import com.google.common.collect.Sets;
* When the rule is changed in Apollo, it will take effect in real time.
*
* @author Jason Song
* @author Haojun Ren
*/
public class ApolloDataSource<T> extends AbstractDataSource<String, T> {

@@ -27,6 +28,8 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> {
private final String flowRulesKey;
private final String defaultFlowRuleValue;

private ConfigChangeListener configChangeListener;

/**
* Constructs the Apollo data source
*
@@ -72,7 +75,7 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> {
}

private void initializeConfigChangeListener() {
config.addChangeListener(new ConfigChangeListener() {
configChangeListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
ConfigChange change = changeEvent.getChange(flowRulesKey);
@@ -82,7 +85,8 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> {
}
loadAndUpdateRules();
}
}, Sets.newHashSet(flowRulesKey));
};
config.addChangeListener(configChangeListener, Sets.newHashSet(flowRulesKey));
}

@Override
@@ -92,6 +96,6 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> {

@Override
public void close() throws Exception {
// nothing to destroy
config.removeChangeListener(configChangeListener);
}
}

Načítá se…
Zrušit
Uložit