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 dffbbdf
Showing 1 changed file with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@
package org.apache.shenyu.admin.listener;

import org.apache.shenyu.common.constant.DefaultPathConstants;
import org.apache.shenyu.common.dto.AppAuthData;
import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.dto.ProxySelectorData;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.dto.DiscoverySyncData;
import org.apache.shenyu.common.dto.*;
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 +55,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

0 comments on commit dffbbdf

Please sign in to comment.