feat: 1.3.0

1.优化代码
2.添加部分代码的描述
This commit is contained in:
www.byteblogs.com 2023-05-14 22:32:36 +08:00 committed by byteblogs168
parent 4916fad455
commit c2aa5ba79a
11 changed files with 93 additions and 26 deletions

View File

@ -8,8 +8,12 @@ import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
import java.util.List; import java.util.List;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH.BATCH_REPORT;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH.BEAT;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH.CONFIG;
/** /**
* netty 客户端请求服务端 * netty 客户端请求
* *
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2023-05-11 21:28 * @date : 2023-05-11 21:28
@ -17,13 +21,13 @@ import java.util.List;
*/ */
public interface NettyClient { public interface NettyClient {
@Mapping(method = RequestMethod.GET, path = "/config") @Mapping(method = RequestMethod.GET, path = CONFIG)
Result getConfig(Integer version); Result getConfig(Integer version);
@Mapping(method = RequestMethod.GET, path = "/beat") @Mapping(method = RequestMethod.GET, path = BEAT)
Result beat(String mark); Result beat(String mark);
@Mapping(method = RequestMethod.POST, path = "/batch/report") @Mapping(method = RequestMethod.POST, path = BATCH_REPORT)
NettyResult reportRetryInfo(List<RetryTaskDTO> list); NettyResult reportRetryInfo(List<RetryTaskDTO> list);
} }

View File

@ -3,6 +3,7 @@ package com.aizuda.easy.retry.client.core.client.netty;
import com.aizuda.easy.retry.client.core.client.NettyClient; import com.aizuda.easy.retry.client.core.client.NettyClient;
import com.aizuda.easy.retry.client.core.client.proxy.RequestBuilder; import com.aizuda.easy.retry.client.core.client.proxy.RequestBuilder;
import com.aizuda.easy.retry.client.core.config.EasyRetryProperties; import com.aizuda.easy.retry.client.core.config.EasyRetryProperties;
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.core.context.SpringContext; import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.common.core.log.LogUtils; import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.NettyResult; import com.aizuda.easy.retry.common.core.model.NettyResult;
@ -17,9 +18,14 @@ import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.BEAT.PING;
/** /**
* netty 客户端处理器
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 18:30 * @date : 2022-03-07 18:30
* @since 1.0.0
*/ */
@Slf4j @Slf4j
public class NettyHttpClientHandler extends SimpleChannelInboundHandler<FullHttpResponse> { public class NettyHttpClientHandler extends SimpleChannelInboundHandler<FullHttpResponse> {
@ -106,7 +112,7 @@ public class NettyHttpClientHandler extends SimpleChannelInboundHandler<FullHttp
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
LogUtils.debug(log,"userEventTriggered"); LogUtils.debug(log,"userEventTriggered");
if (evt instanceof IdleStateEvent) { if (evt instanceof IdleStateEvent) {
client.beat("PING"); client.beat(PING);
} else { } else {
super.userEventTriggered(ctx, evt); super.userEventTriggered(ctx, evt);
} }

View File

@ -13,6 +13,8 @@ import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
* 处理请求服务端时需要存储的中间值
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2023-05-12 09:05 * @date : 2023-05-12 09:05
* @since 1.3.0 * @since 1.3.0

View File

@ -1,26 +1,64 @@
package com.aizuda.easy.retry.common.core.constant; package com.aizuda.easy.retry.common.core.constant;
/** /**
* 系统通用常量
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-04-17 10:47 * @date : 2022-04-17 10:47
* @since 1.0.0
*/ */
public class SystemConstants { public interface SystemConstants {
/** /**
* 请求头 key * 请求头 key
*/ */
public static final String EASY_RETRY_HEAD_KEY = "easy-retry"; String EASY_RETRY_HEAD_KEY = "easy-retry";
/** /**
* 异常重试码 key * 异常重试码 key
*/ */
public static final String EASY_RETRY_STATUS_CODE_KEY = "easy-retry-status"; String EASY_RETRY_STATUS_CODE_KEY = "easy-retry-status";
/** /**
* 异常重试码 * 异常重试码
*/ */
public static final String EASY_RETRY_STATUS_CODE = "519"; String EASY_RETRY_STATUS_CODE = "519";
/**
* 心跳
*/
interface BEAT {
/**
* PING
*/
String PING = "PING";
/**
* PONG
*/
String PONG = "PONG";
}
/**
* 请求路径
*/
interface HTTP_PATH {
/**
* 心跳请求
*/
String BEAT = "/beat";
/**
* 同步配置
*/
String CONFIG = "/config";
/**
* 批量上报
*/
String BATCH_REPORT = "/batch/report";
}
} }

View File

@ -21,8 +21,11 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
* netty server
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 15:54 * @date : 2022-03-07 15:54
* @since 1.0.0
*/ */
@Component @Component
@Slf4j @Slf4j

View File

@ -1,6 +1,8 @@
package com.aizuda.easy.retry.server.server.handler; package com.aizuda.easy.retry.server.server.handler;
import cn.hutool.core.net.url.UrlQuery; import cn.hutool.core.net.url.UrlQuery;
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH;
import com.aizuda.easy.retry.common.core.log.LogUtils; import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.handler.ClientRegisterHandler; import com.aizuda.easy.retry.server.support.handler.ClientRegisterHandler;
import com.aizuda.easy.retry.common.core.model.NettyResult; import com.aizuda.easy.retry.common.core.model.NettyResult;
@ -12,22 +14,22 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.BEAT.PONG;
/** /**
* 接收心跳请求
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 16:26 * @date : 2022-03-07 16:26
* @since 1.0.0
*/ */
@Component @Component
@Slf4j @Slf4j
public class BeatHttpRequestHandler extends GetHttpRequestHandler { public class BeatHttpRequestHandler extends GetHttpRequestHandler {
@Autowired
private ClientRegisterHandler clientRegisterHandler;
private static final String URI = "/beat";
@Override @Override
public boolean supports(String uri) { public boolean supports(String path) {
return URI.equals(uri); return HTTP_PATH.BEAT.equals(path);
} }
@Override @Override
@ -39,6 +41,6 @@ public class BeatHttpRequestHandler extends GetHttpRequestHandler {
public String doHandler(String content, UrlQuery query, HttpHeaders headers) { public String doHandler(String content, UrlQuery query, HttpHeaders headers) {
LogUtils.info(log,"Beat check content:[{}]", content); LogUtils.info(log,"Beat check content:[{}]", content);
EasyRetryRequest retryRequest = JsonUtil.parseObject(content, EasyRetryRequest.class); EasyRetryRequest retryRequest = JsonUtil.parseObject(content, EasyRetryRequest.class);
return JsonUtil.toJsonString(new NettyResult("PONG", retryRequest.getReqId())); return JsonUtil.toJsonString(new NettyResult(PONG, retryRequest.getReqId()));
} }
} }

View File

@ -14,9 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH.CONFIG;
/** /**
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 16:29 * @date : 2022-03-07 16:29
* @since 1.0.0
*/ */
@Component @Component
@Slf4j @Slf4j
@ -26,11 +29,9 @@ public class ConfigHttpRequestHandler extends GetHttpRequestHandler {
@Qualifier("configAccessProcessor") @Qualifier("configAccessProcessor")
private ConfigAccess configAccess; private ConfigAccess configAccess;
private static final String URI = "/config";
@Override @Override
public boolean supports(String uri) { public boolean supports(String path) {
return URI.equals(uri); return CONFIG.equals(path);
} }
@Override @Override

View File

@ -5,8 +5,11 @@ import cn.hutool.core.net.url.UrlQuery;
import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;
/** /**
* 处理GRT请求
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 17:35 * @date : 2022-03-07 17:35
* @since 1.0.0
*/ */
public abstract class GetHttpRequestHandler implements HttpRequestHandler { public abstract class GetHttpRequestHandler implements HttpRequestHandler {

View File

@ -5,12 +5,15 @@ import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpMethod;
/** /**
* 处理http请求
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 16:23 * @date : 2022-03-07 16:23
* @since 1.0.0
*/ */
public interface HttpRequestHandler { public interface HttpRequestHandler {
boolean supports(String uri); boolean supports(String path);
HttpMethod method(); HttpMethod method();

View File

@ -5,8 +5,11 @@ import cn.hutool.core.net.url.UrlQuery;
import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;
/** /**
* 处理POST请求
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 17:35 * @date : 2022-03-07 17:35
* @since 1.0.0
*/ */
public abstract class PostHttpRequestHandler implements HttpRequestHandler { public abstract class PostHttpRequestHandler implements HttpRequestHandler {

View File

@ -14,23 +14,25 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import static com.aizuda.easy.retry.common.core.constant.SystemConstants.HTTP_PATH.BATCH_REPORT;
/** /**
* 处理上报数据
*
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2022-03-07 16:39 * @date : 2022-03-07 16:39
* @since 1.0.0
*/ */
@Component @Component
@Slf4j @Slf4j
public class ReportRetryInfoHttpRequestHandler extends PostHttpRequestHandler { public class ReportRetryInfoHttpRequestHandler extends PostHttpRequestHandler {
private static final String URI = "/batch/report";
@Autowired @Autowired
private RetryService retryService; private RetryService retryService;
@Override @Override
public boolean supports(String uri) { public boolean supports(String path) {
return URI.equals(uri); return BATCH_REPORT.equals(path);
} }
@Override @Override