From 7367da6936539053966c273fb5b3ff5263652433 Mon Sep 17 00:00:00 2001
From: Neptune <42354711+HaojunRen@users.noreply.github.com>
Date: Mon, 11 Mar 2019 11:39:47 +0800
Subject: [PATCH] Upgrade apollo-client to 1.3.0 and add support for removing
listener in sentinel-datasource-apollo (#562)
- Add to unsubscribe config change event
---
sentinel-extension/sentinel-datasource-apollo/pom.xml | 2 +-
.../sentinel/datasource/apollo/ApolloDataSource.java | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/sentinel-extension/sentinel-datasource-apollo/pom.xml b/sentinel-extension/sentinel-datasource-apollo/pom.xml
index e01adc37..9a169fac 100644
--- a/sentinel-extension/sentinel-datasource-apollo/pom.xml
+++ b/sentinel-extension/sentinel-datasource-apollo/pom.xml
@@ -12,7 +12,7 @@
sentinel-datasource-apollo
- 1.0.0
+ 1.3.0
diff --git a/sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java b/sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java
index 9a7898de..45bf0a61 100644
--- a/sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java
+++ b/sentinel-extension/sentinel-datasource-apollo/src/main/java/com/alibaba/csp/sentinel/datasource/apollo/ApolloDataSource.java
@@ -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 extends AbstractDataSource {
@@ -27,6 +28,8 @@ public class ApolloDataSource extends AbstractDataSource {
private final String flowRulesKey;
private final String defaultFlowRuleValue;
+ private ConfigChangeListener configChangeListener;
+
/**
* Constructs the Apollo data source
*
@@ -72,7 +75,7 @@ public class ApolloDataSource extends AbstractDataSource {
}
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 extends AbstractDataSource {
}
loadAndUpdateRules();
}
- }, Sets.newHashSet(flowRulesKey));
+ };
+ config.addChangeListener(configChangeListener, Sets.newHashSet(flowRulesKey));
}
@Override
@@ -92,6 +96,6 @@ public class ApolloDataSource extends AbstractDataSource {
@Override
public void close() throws Exception {
- // nothing to destroy
+ config.removeChangeListener(configChangeListener);
}
}