String url = Constants.CONFIG_CONTROLLER_PATH;
Map<String, String> params = new HashMap<String, String>(6);
params.put("dataId", dataId);
params.put("group", group);
params.put("content", content);
params.put("type", type);
if (StringUtils.isNotEmpty(tenant)) {
params.put("tenant", tenant);
}
if (StringUtils.isNotEmpty(appName)) {
params.put("appName", appName);
}
if (StringUtils.isNotEmpty(tag)) {
params.put("tag", tag);
}
Map<String, String> headers = new HashMap<String, String>(1);
if (StringUtils.isNotEmpty(betaIps)) {
headers.put("betaIps", betaIps);
}
HttpRestResult<String> result = null;
try {
result = agent.httpPost(url, headers, params, encode, POST_TIMEOUT);
} catch (Exception ex) {
LOGGER.warn("[{}] [publish-single] exception, dataId={}, group={}, msg={}", agent.getName(), dataId, group,
ex.toString());
return false;
}
推送配置源码:com.alibaba.nacos.client.config.NacosConfigService#publishConfigInner
移除配置:com.alibaba.nacos.client.config.NacosConfigService#removeConfig
String url = Constants.CONFIG_CONTROLLER_PATH;
Map<String, String> params = new HashMap<String, String>(4);
params.put("dataId", dataId);
params.put("group", group);
if (StringUtils.isNotEmpty(tenant)) {
params.put("tenant", tenant);
}
if (StringUtils.isNotEmpty(tag)) {
params.put("tag", tag);
}
HttpRestResult<String> result = null;
try {
result = agent.httpDelete(url, null, params, encode, POST_TIMEOUT);
} catch (Exception ex) {
LOGGER.warn("[remove] error, " + dataId + ", " + group + ", " + tenant + ", msg: " + ex.toString());
return false;
}
注意到了吗?nacos-client是使用restful api风格。 获取配置是get,推送配置是post,移除配置是delete