Skip to content

Commit

Permalink
fix consul sync problem (apache#5545)
Browse files Browse the repository at this point in the history
  • Loading branch information
王一飞 committed Apr 13, 2024
1 parent e806f61 commit f26f953
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.dto.DiscoverySyncData;
import org.apache.shenyu.common.enums.DataEventTypeEnum;
import org.apache.shenyu.common.exception.ShenyuException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
Expand Down Expand Up @@ -64,21 +61,16 @@ public void onAppAuthChanged(final List<AppAuthData> changed, final DataEventTyp
@Override
public void onMetaDataChanged(final List<MetaData> changed, final DataEventTypeEnum eventType) {
for (MetaData data : changed) {
try {
String metaDataPath = DefaultPathConstants.buildMetaDataPath(URLEncoder.encode(data.getPath(), "UTF-8"));
// delete
if (eventType == DataEventTypeEnum.DELETE) {
deleteNode(metaDataPath);
LOG.debug("[DataChangedListener] delete appKey {}", metaDataPath);
continue;
}
// create or update
createOrUpdate(metaDataPath, data);
LOG.debug("[DataChangedListener] change metaDataPath {}", metaDataPath);
} catch (UnsupportedEncodingException e) {
LOG.error("[DataChangedListener] url encode error.", e);
throw new ShenyuException(e.getMessage());
String metaDataPath = DefaultPathConstants.buildMetaDataPath(data.getPath());
// delete
if (eventType == DataEventTypeEnum.DELETE) {
deleteNode(metaDataPath);
LOG.debug("[DataChangedListener] delete appKey {}", metaDataPath);
continue;
}
// create or update
createOrUpdate(metaDataPath, data);
LOG.debug("[DataChangedListener] change metaDataPath {}", metaDataPath);
}
}

Expand Down Expand Up @@ -196,4 +188,4 @@ public void onRuleChanged(final List<RuleData> changed, final DataEventTypeEnum
* @param selectorParentPath selectorParentPath
*/
public abstract void deletePathRecursive(String selectorParentPath);
}
}

0 comments on commit f26f953

Please sign in to comment.