feat(sj_1.0.0): 优化同步配置逻辑
This commit is contained in:
parent
0005ce430d
commit
2a18fbc944
@ -4,8 +4,6 @@ import com.aizuda.snailjob.client.common.annotation.Mapping;
|
|||||||
import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
||||||
import com.aizuda.snailjob.common.core.constant.SystemConstants.HTTP_PATH;
|
import com.aizuda.snailjob.common.core.constant.SystemConstants.HTTP_PATH;
|
||||||
import com.aizuda.snailjob.common.core.model.Result;
|
import com.aizuda.snailjob.common.core.model.Result;
|
||||||
import com.aizuda.snailjob.client.common.annotation.Mapping;
|
|
||||||
import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +16,7 @@ import com.aizuda.snailjob.client.common.rpc.client.RequestMethod;
|
|||||||
public interface NettyClient {
|
public interface NettyClient {
|
||||||
|
|
||||||
@Mapping(method = RequestMethod.GET, path = HTTP_PATH.SYNC_CONFIG)
|
@Mapping(method = RequestMethod.GET, path = HTTP_PATH.SYNC_CONFIG)
|
||||||
Result getConfig(Integer version);
|
Result syncRemoteConfig();
|
||||||
|
|
||||||
@Mapping(method = RequestMethod.GET, path = HTTP_PATH.BEAT)
|
@Mapping(method = RequestMethod.GET, path = HTTP_PATH.BEAT)
|
||||||
Result beat(String mark);
|
Result beat(String mark);
|
||||||
|
@ -31,23 +31,18 @@ public class SyncRemoteConfig implements Lifecycle {
|
|||||||
|
|
||||||
SCHEDULE_EXECUTOR.scheduleAtFixedRate(() -> {
|
SCHEDULE_EXECUTOR.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
try {
|
NettyClient client = RequestBuilder.<NettyClient, NettyResult>newBuilder()
|
||||||
NettyClient client = RequestBuilder.<NettyClient, NettyResult>newBuilder()
|
.client(NettyClient.class)
|
||||||
.client(NettyClient.class)
|
.callback(nettyResult -> {
|
||||||
.callback(nettyResult -> {
|
if (Objects.isNull(nettyResult.getData())) {
|
||||||
if (Objects.isNull(nettyResult.getData())) {
|
SnailJobLog.LOCAL.error("获取配置结果为null");
|
||||||
SnailJobLog.LOCAL.error("获取配置结果为null");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GroupVersionCache.setConfig(
|
GroupVersionCache.setConfig(
|
||||||
JsonUtil.parseObject(nettyResult.getData().toString(), ConfigDTO.class));
|
JsonUtil.parseObject(nettyResult.getData().toString(), ConfigDTO.class));
|
||||||
})
|
}).build();
|
||||||
.build();
|
client.syncRemoteConfig();
|
||||||
client.getConfig(0);
|
|
||||||
} catch (Exception e) {
|
|
||||||
SnailJobLog.LOCAL.error("同步版本失败", e);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SnailJobLog.LOCAL.error("通知配置失败", e);
|
SnailJobLog.LOCAL.error("通知配置失败", e);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ public class ConfigHttpRequestHandler extends GetHttpRequestHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String doHandler(String content, UrlQuery urlQuery, HttpHeaders headers) {
|
public String doHandler(String content, UrlQuery urlQuery, HttpHeaders headers) {
|
||||||
SnailJobLog.LOCAL.info("版本同步 content:[{}]", urlQuery.toString());
|
|
||||||
SnailJobRequest retryRequest = JsonUtil.parseObject(content, SnailJobRequest.class);
|
SnailJobRequest retryRequest = JsonUtil.parseObject(content, SnailJobRequest.class);
|
||||||
String groupName = headers.get(HeadersEnum.GROUP_NAME.getKey());
|
String groupName = headers.get(HeadersEnum.GROUP_NAME.getKey());
|
||||||
String namespace = headers.get(HeadersEnum.NAMESPACE.getKey());
|
String namespace = headers.get(HeadersEnum.NAMESPACE.getKey());
|
||||||
|
Loading…
Reference in New Issue
Block a user