fix:0.0.4.3

修复客户端配置了server.servlet.context-pat,请求重试接口404 问题
This commit is contained in:
byteblogs168 2023-01-09 15:54:07 +08:00
parent 6fff77dfa0
commit 1a049541c1
9 changed files with 50 additions and 40 deletions

View File

@ -26,7 +26,7 @@ CREATE TABLE `notify_config`
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', `update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `idx_group_name` (`group_name`) KEY `idx_group_name` (`group_name`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='通知配置' ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='通知配置'
; ;
@ -71,23 +71,23 @@ CREATE TABLE `retry_task_0`
CREATE TABLE `retry_task_log` CREATE TABLE `retry_task_log`
( (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`group_name` varchar(64) NOT NULL COMMENT '组名称', `group_name` varchar(64) NOT NULL COMMENT '组名称',
`scene_name` varchar(64) NOT NULL COMMENT '场景名称', `scene_name` varchar(64) NOT NULL COMMENT '场景名称',
`biz_id` varchar(64) NOT NULL COMMENT '业务id', `biz_id` varchar(64) NOT NULL COMMENT '业务id',
`biz_no` varchar(64) NOT NULL DEFAULT '' COMMENT '业务编号', `biz_no` varchar(64) NOT NULL DEFAULT '' COMMENT '业务编号',
`executor_name` varchar(512) NOT NULL DEFAULT '' COMMENT '执行器名称', `executor_name` varchar(512) NOT NULL DEFAULT '' COMMENT '执行器名称',
`args_str` text NOT NULL COMMENT '执行方法参数', `args_str` text NOT NULL COMMENT '执行方法参数',
`ext_attrs` text NOT NULL COMMENT '扩展字段', `ext_attrs` text NOT NULL COMMENT '扩展字段',
`retry_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '重试状态 0、失败 1、成功', `retry_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '重试状态 0、失败 1、成功',
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', `update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`error_message` text NOT NULL COMMENT '异常信息', `error_message` text NOT NULL COMMENT '异常信息',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `idx_group_name` (`group_name`), KEY `idx_group_name` (`group_name`),
KEY `idx_scene_name` (`scene_name`), KEY `idx_scene_name` (`scene_name`),
KEY `idx_retry_status` (`retry_status`), KEY `idx_retry_status` (`retry_status`),
KEY `idx_biz_id` (`biz_id`) KEY `idx_biz_id` (`biz_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='重试日志表' ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='重试日志表'
; ;
@ -100,7 +100,7 @@ CREATE TABLE `scene_config`
`max_retry_count` int(11) NOT NULL DEFAULT '5' COMMENT '最大重试次数', `max_retry_count` int(11) NOT NULL DEFAULT '5' COMMENT '最大重试次数',
`back_off` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1、默认等级 2、固定间隔时间 3、CRON 表达式', `back_off` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1、默认等级 2、固定间隔时间 3、CRON 表达式',
`trigger_interval` varchar(16) NOT NULL DEFAULT '' COMMENT '间隔时长', `trigger_interval` varchar(16) NOT NULL DEFAULT '' COMMENT '间隔时长',
`deadline_request` bigint(20) unsigned NOT NULL DEFAULT '60000' COMMENT 'Deadline Request 调用链超时 单位毫秒', `deadline_request` bigint(20) unsigned NOT NULL DEFAULT '60000' COMMENT 'Deadline Request 调用链超时 单位毫秒',
`description` varchar(256) NOT NULL DEFAULT '' COMMENT '描述', `description` varchar(256) NOT NULL DEFAULT '' COMMENT '描述',
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', `update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
@ -111,15 +111,16 @@ CREATE TABLE `scene_config`
CREATE TABLE `server_node` CREATE TABLE `server_node`
( (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`group_name` varchar(64) NOT NULL COMMENT '组名称', `group_name` varchar(64) NOT NULL COMMENT '组名称',
`host_id` varchar(64) NOT NULL COMMENT '主机id', `host_id` varchar(64) NOT NULL COMMENT '主机id',
`host_ip` varchar(64) NOT NULL COMMENT '机器ip', `host_ip` varchar(64) NOT NULL COMMENT '机器ip',
`host_port` int(16) NOT NULL COMMENT '机器ip', `context_path` varchar(256) NOT NULL COMMENT '客户端上下文路径 server.servlet.context-path',
`expire_at` datetime NOT NULL COMMENT '过期时间', `host_port` int(16) NOT NULL COMMENT '机器端口',
`node_type` tinyint(4) NOT NULL COMMENT '节点类型 1、客户端 2、是服务端', `expire_at` datetime NOT NULL COMMENT '过期时间',
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `node_type` tinyint(4) NOT NULL COMMENT '节点类型 1、客户端 2、是服务端',
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', `create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `uk_host_id_host_ip` (`host_id`,`host_ip`) UNIQUE KEY `uk_host_id_host_ip` (`host_id`,`host_ip`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='服务器节点' ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='服务器节点'

View File

@ -18,16 +18,16 @@ import io.netty.handler.codec.http.*;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.IdleStateHandler;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -51,6 +51,7 @@ public class NettyHttpConnectClient implements Lifecycle, ApplicationContextAwar
try { try {
XRetryProperties xRetryProperties = applicationContext.getBean(XRetryProperties.class); XRetryProperties xRetryProperties = applicationContext.getBean(XRetryProperties.class);
XRetryProperties.ServerConfig server = xRetryProperties.getServer(); XRetryProperties.ServerConfig server = xRetryProperties.getServer();
final NettyHttpConnectClient thisClient = this; final NettyHttpConnectClient thisClient = this;
bootstrap.group(nioEventLoopGroup) bootstrap.group(nioEventLoopGroup)
@ -100,7 +101,7 @@ public class NettyHttpConnectClient implements Lifecycle, ApplicationContextAwar
FullHttpRequest request = new DefaultFullHttpRequest( FullHttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_0, method, url, Unpooled.wrappedBuffer(body.getBytes(StandardCharsets.UTF_8))); HttpVersion.HTTP_1_0, method, url, Unpooled.wrappedBuffer(body.getBytes(StandardCharsets.UTF_8)));
Environment environment = SpringContext.applicationContext.getBean(Environment.class); ServerProperties serverProperties = SpringContext.applicationContext.getBean(ServerProperties.class);
request.headers() request.headers()
.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON) .set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)
@ -111,7 +112,8 @@ public class NettyHttpConnectClient implements Lifecycle, ApplicationContextAwar
.set(HeadersEnum.HOST_ID.getKey(), HOST_ID) .set(HeadersEnum.HOST_ID.getKey(), HOST_ID)
.set(HeadersEnum.HOST_IP.getKey(), HOST_IP) .set(HeadersEnum.HOST_IP.getKey(), HOST_IP)
.set(HeadersEnum.GROUP_NAME.getKey(), XRetryProperties.getGroup()) .set(HeadersEnum.GROUP_NAME.getKey(), XRetryProperties.getGroup())
.set(HeadersEnum.HOST_PORT.getKey(), environment.getProperty("server.port", Integer.class)) .set(HeadersEnum.CONTEXT_PATH.getKey(), Optional.ofNullable(serverProperties.getServlet().getContextPath()).orElse("/"))
.set(HeadersEnum.HOST_PORT.getKey(), Optional.ofNullable(serverProperties.getPort()).orElse(8080))
.set(HeadersEnum.VERSION.getKey(), GroupVersionCache.getVersion()) .set(HeadersEnum.VERSION.getKey(), GroupVersionCache.getVersion())
; ;

View File

@ -1,6 +1,5 @@
package com.x.retry.client.core.event; package com.x.retry.client.core.event;
import cn.hutool.extra.ssh.JschUtil;
import com.x.retry.common.core.util.JsonUtil; import com.x.retry.common.core.util.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -13,6 +13,7 @@ public enum HeadersEnum {
HOST_IP("host-ip"), HOST_IP("host-ip"),
HOST_PORT("host-port"), HOST_PORT("host-port"),
GROUP_NAME("group-name"), GROUP_NAME("group-name"),
CONTEXT_PATH("context-path"),
REQUEST_ID("request-id"), REQUEST_ID("request-id"),
VERSION("version"), VERSION("version"),
; ;

View File

@ -25,10 +25,12 @@ public class ServerNode implements Serializable {
private Integer nodeType; private Integer nodeType;
private String contextPath;
private LocalDateTime createDt; private LocalDateTime createDt;
private LocalDateTime updateDt; private LocalDateTime updateDt;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -58,6 +58,7 @@ public class MybatisRetryTaskAccess extends AbstractRetryTaskAccess {
@Override @Override
public int updateRetryTask(RetryTask retryTask) { public int updateRetryTask(RetryTask retryTask) {
setPartition(retryTask.getGroupName()); setPartition(retryTask.getGroupName());
retryTask.setUpdateDt(LocalDateTime.now());
return retryTaskMapper.updateById(retryTask); return retryTaskMapper.updateById(retryTask);
} }

View File

@ -46,7 +46,7 @@ import java.util.concurrent.Callable;
public class ExecUnitActor extends AbstractActor { public class ExecUnitActor extends AbstractActor {
public static final String BEAN_NAME = "ExecUnitActor"; public static final String BEAN_NAME = "ExecUnitActor";
public static final String URL = "http://{0}:{1}/retry/dispatch/v1"; public static final String URL = "http://{0}:{1}/{2}/retry/dispatch/v1";
@Autowired @Autowired
@Qualifier("bitSetIdempotentStrategyHandler") @Qualifier("bitSetIdempotentStrategyHandler")
@ -118,7 +118,7 @@ public class ExecUnitActor extends AbstractActor {
HttpEntity<DispatchRetryDTO> requestEntity = new HttpEntity<>(dispatchRetryDTO, requestHeaders); HttpEntity<DispatchRetryDTO> requestEntity = new HttpEntity<>(dispatchRetryDTO, requestHeaders);
String format = MessageFormat.format(URL, serverNode.getHostIp(), serverNode.getHostPort().toString()); String format = MessageFormat.format(URL, serverNode.getHostIp(), serverNode.getHostPort().toString(), serverNode.getContextPath());
Result result = restTemplate.postForObject(format, requestEntity, Result.class); Result result = restTemplate.postForObject(format, requestEntity, Result.class);
if (1 != result.getStatus() && StringUtils.isNotBlank(result.getMessage())) { if (1 != result.getStatus() && StringUtils.isNotBlank(result.getMessage())) {

View File

@ -47,6 +47,7 @@ public class ClientRegisterHandler {
String hostIp = headers.get(HeadersEnum.HOST_IP.getKey()); String hostIp = headers.get(HeadersEnum.HOST_IP.getKey());
Integer hostPort = headers.getInt(HeadersEnum.HOST_PORT.getKey()); Integer hostPort = headers.getInt(HeadersEnum.HOST_PORT.getKey());
String groupName = headers.get(HeadersEnum.GROUP_NAME.getKey()); String groupName = headers.get(HeadersEnum.GROUP_NAME.getKey());
String contextPath = headers.get(HeadersEnum.CONTEXT_PATH.getKey());
LocalDateTime endTime = LocalDateTime.now().plusSeconds(30); LocalDateTime endTime = LocalDateTime.now().plusSeconds(30);
ServerNode serverNode = new ServerNode(); ServerNode serverNode = new ServerNode();
@ -56,6 +57,7 @@ public class ClientRegisterHandler {
serverNode.setHostIp(hostIp); serverNode.setHostIp(hostIp);
serverNode.setExpireAt(endTime); serverNode.setExpireAt(endTime);
serverNode.setCreateDt(LocalDateTime.now()); serverNode.setCreateDt(LocalDateTime.now());
serverNode.setContextPath(contextPath);
serverNode.setHostId(hostId); serverNode.setHostId(hostId);
try { try {

View File

@ -9,28 +9,30 @@
<result column="host_port" jdbcType="INTEGER" property="hostPort" /> <result column="host_port" jdbcType="INTEGER" property="hostPort" />
<result column="expire_at" jdbcType="TIMESTAMP" property="expireAt" /> <result column="expire_at" jdbcType="TIMESTAMP" property="expireAt" />
<result column="node_type" jdbcType="TINYINT" property="nodeType" /> <result column="node_type" jdbcType="TINYINT" property="nodeType" />
<result column="context_path" jdbcType="VARCHAR" property="contextPath" />
<result column="create_dt" jdbcType="TIMESTAMP" property="createDt" /> <result column="create_dt" jdbcType="TIMESTAMP" property="createDt" />
<result column="update_dt" jdbcType="TIMESTAMP" property="updateDt" /> <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, group_name, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
</sql> </sql>
<insert id="insertOrUpdate" parameterType="com.x.retry.server.persistence.mybatis.po.ServerNode"> <insert id="insertOrUpdate" parameterType="com.x.retry.server.persistence.mybatis.po.ServerNode">
insert into server_node (id, group_name, host_id, host_ip, host_port, insert into server_node (id, group_name, host_id, host_ip, host_port,
expire_at, node_type, create_dt) expire_at, node_type, context_path, create_dt)
values (#{id,jdbcType=BIGINT}, #{groupName,jdbcType=VARCHAR}, #{hostId,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR}, values (#{id,jdbcType=BIGINT}, #{groupName,jdbcType=VARCHAR}, #{hostId,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR},
#{hostPort,jdbcType=INTEGER}, #{hostPort,jdbcType=INTEGER},
#{expireAt,jdbcType=TIMESTAMP}, #{nodeType,jdbcType=TINYINT}, #{createDt,jdbcType=TIMESTAMP} #{expireAt,jdbcType=TIMESTAMP}, #{nodeType,jdbcType=TINYINT}, #{contextPath,jdbcType=VARCHAR}, #{createDt,jdbcType=TIMESTAMP}
) ON DUPLICATE KEY UPDATE ) ON DUPLICATE KEY UPDATE
host_id = values(`host_id`), host_id = values(`host_id`),
host_ip = values(`host_ip`), host_ip = values(`host_ip`),
host_port = values(`host_port`), host_port = values(`host_port`),
expire_at = values(`expire_at`), expire_at = values(`expire_at`),
node_type = values(`node_type`), node_type = values(`node_type`),
create_dt = values(`create_dt`) create_dt = values(`create_dt`),
context_path = values(`context_path`)
</insert> </insert>
<delete id="deleteByExpireAt"> <delete id="deleteByExpireAt">
delete from server_node delete from server_node
where expire_at &lt;= #{endTime,jdbcType=TIMESTAMP} where expire_at &lt;= #{endTime,jdbcType=TIMESTAMP}
</delete> </delete>
</mapper> </mapper>