Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade apollo-client to 1.3.0 version & Add to unsubscribe config change event #562

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentinel-extension/sentinel-datasource-apollo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
* 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> {

private final Config config;
private final String flowRulesKey;
private final String defaultFlowRuleValue;

private ConfigChangeListener configChangeListener;

/**
* Constructs the Apollo data source
*
Expand Down Expand Up @@ -72,7 +75,7 @@ private void loadAndUpdateRules() {
}

private void initializeConfigChangeListener() {
config.addChangeListener(new ConfigChangeListener() {
configChangeListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
ConfigChange change = changeEvent.getChange(flowRulesKey);
Expand All @@ -82,7 +85,8 @@ public void onChange(ConfigChangeEvent changeEvent) {
}
loadAndUpdateRules();
}
}, Sets.newHashSet(flowRulesKey));
};
config.addChangeListener(configChangeListener, Sets.newHashSet(flowRulesKey));
}

@Override
Expand All @@ -92,6 +96,6 @@ public String readSource() throws Exception {

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