use of com.alibaba.nacos.api.config.listener.Listener in project spring-cloud-alibaba by alibaba.
the class NacosContextRefresher method registerNacosListener.
private void registerNacosListener(final String groupKey, final String dataKey) {
String key = NacosPropertySourceRepository.getMapKey(dataKey, groupKey);
Listener listener = listenerMap.computeIfAbsent(key, lst -> new AbstractSharedListener() {
@Override
public void innerReceive(String dataId, String group, String configInfo) {
refreshCountIncrement();
nacosRefreshHistory.addRefreshRecord(dataId, group, configInfo);
// todo feature: support single refresh for listening
applicationContext.publishEvent(new RefreshEvent(this, null, "Refresh Nacos config"));
if (log.isDebugEnabled()) {
log.debug(String.format("Refresh Nacos config group=%s,dataId=%s,configInfo=%s", group, dataId, configInfo));
}
}
});
try {
configService.addListener(dataKey, groupKey, listener);
} catch (NacosException e) {
log.warn(String.format("register fail for nacos listener ,dataId=[%s],group=[%s]", dataKey, groupKey), e);
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project incubator-shenyu by apache.
the class NacosCacheHandler method watcherData.
protected void watcherData(final String dataId, final OnChange oc) {
Listener listener = new Listener() {
@Override
public void receiveConfigInfo(final String configInfo) {
oc.change(configInfo);
}
@Override
public Executor getExecutor() {
return null;
}
};
oc.change(getConfigAndSignListener(dataId, listener));
LISTENERS.computeIfAbsent(dataId, key -> new ArrayList<>()).add(listener);
}
use of com.alibaba.nacos.api.config.listener.Listener in project solon by noear.
the class CloudConfigServiceNacosImp method attention.
/**
* 关注配置
*/
@Override
public void attention(String group, String key, CloudConfigHandler observer) {
if (observerMap.containsKey(observer)) {
return;
}
if (Utils.isEmpty(group)) {
group = Solon.cfg().appGroup();
}
CloudConfigObserverEntity entity = new CloudConfigObserverEntity(group, key, observer);
observerMap.put(observer, entity);
try {
group = groupReview(group);
real.addListener(key, group, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String value) {
entity.handle(new Config(entity.group, entity.key, value, 0));
}
});
} catch (NacosException ex) {
throw new RuntimeException(ex);
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project hummer-framework by hummer-team.
the class GatewayContextInit method loadNacosConfig.
private void loadNacosConfig() throws NacosException, IOException {
Properties properties = getConfigServerProperties();
properties.setProperty("namespace", "bumblebee-service-panli-com");
String groupId = PropertiesContainer.valueOfString("config.center.gateway.group.id", "DEFAULT_GROUP");
long timeoutMillis = PropertiesContainer.valueOf("config.center.gateway.timeout.millis", Long.class, 5000L);
// load all gateway group config
ConfigService configService = NacosFactory.createConfigService(properties);
String val = configService.getConfigAndSignListener(getDataIdByEvn(), groupId, timeoutMillis, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
try {
fillByProperties(configInfo, getDataIdByEvn(), groupId);
registerSystemProperty();
registerFlowClusterClientConfig();
registerSentinelSystemRuleConfig();
} catch (IOException e) {
log.warn("reset properties to PropertiesContainer failed", e);
// ignore
}
}
});
fillByProperties(val, getDataIdByEvn(), groupId);
}
use of com.alibaba.nacos.api.config.listener.Listener in project hummer-framework by hummer-team.
the class ListenerConfig method getListener.
private Listener getListener() {
return new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
if (Strings.isNullOrEmpty(configInfo)) {
return;
}
log.debug("refresh config done,config value is \n{}", configInfo);
// parse config instance
DoorGoodConfig doorGoodConfig = JSON.parseObject(configInfo, new TypeReference<DoorGoodConfig>() {
});
// refresh gateway config
refreshGatewayRule(doorGoodConfig);
// refresh sentinel config
refreshSentinelConfig(doorGoodConfig);
}
};
}
Aggregations