fix:0.0.4.3
修复客户端配置了server.servlet.context-pat,请求重试接口404 问题
This commit is contained in:
parent
6fff77dfa0
commit
1a049541c1
@ -115,7 +115,8 @@ CREATE TABLE `server_node`
|
||||
`group_name` varchar(64) NOT NULL COMMENT '组名称',
|
||||
`host_id` varchar(64) NOT NULL COMMENT '主机id',
|
||||
`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',
|
||||
`host_port` int(16) NOT NULL COMMENT '机器端口',
|
||||
`expire_at` datetime NOT NULL COMMENT '过期时间',
|
||||
`node_type` tinyint(4) NOT NULL COMMENT '节点类型 1、客户端 2、是服务端',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
|
@ -18,16 +18,16 @@ import io.netty.handler.codec.http.*;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -51,6 +51,7 @@ public class NettyHttpConnectClient implements Lifecycle, ApplicationContextAwar
|
||||
|
||||
try {
|
||||
XRetryProperties xRetryProperties = applicationContext.getBean(XRetryProperties.class);
|
||||
|
||||
XRetryProperties.ServerConfig server = xRetryProperties.getServer();
|
||||
final NettyHttpConnectClient thisClient = this;
|
||||
bootstrap.group(nioEventLoopGroup)
|
||||
@ -100,7 +101,7 @@ public class NettyHttpConnectClient implements Lifecycle, ApplicationContextAwar
|
||||
FullHttpRequest request = new DefaultFullHttpRequest(
|
||||
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()
|
||||
.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_IP.getKey(), HOST_IP)
|
||||
.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())
|
||||
;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.x.retry.client.core.event;
|
||||
|
||||
import cn.hutool.extra.ssh.JschUtil;
|
||||
import com.x.retry.common.core.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -13,6 +13,7 @@ public enum HeadersEnum {
|
||||
HOST_IP("host-ip"),
|
||||
HOST_PORT("host-port"),
|
||||
GROUP_NAME("group-name"),
|
||||
CONTEXT_PATH("context-path"),
|
||||
REQUEST_ID("request-id"),
|
||||
VERSION("version"),
|
||||
;
|
||||
|
@ -25,6 +25,8 @@ public class ServerNode implements Serializable {
|
||||
|
||||
private Integer nodeType;
|
||||
|
||||
private String contextPath;
|
||||
|
||||
private LocalDateTime createDt;
|
||||
|
||||
private LocalDateTime updateDt;
|
||||
|
@ -58,6 +58,7 @@ public class MybatisRetryTaskAccess extends AbstractRetryTaskAccess {
|
||||
@Override
|
||||
public int updateRetryTask(RetryTask retryTask) {
|
||||
setPartition(retryTask.getGroupName());
|
||||
retryTask.setUpdateDt(LocalDateTime.now());
|
||||
return retryTaskMapper.updateById(retryTask);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ import java.util.concurrent.Callable;
|
||||
public class ExecUnitActor extends AbstractActor {
|
||||
|
||||
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
|
||||
@Qualifier("bitSetIdempotentStrategyHandler")
|
||||
@ -118,7 +118,7 @@ public class ExecUnitActor extends AbstractActor {
|
||||
|
||||
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);
|
||||
|
||||
if (1 != result.getStatus() && StringUtils.isNotBlank(result.getMessage())) {
|
||||
|
@ -47,6 +47,7 @@ public class ClientRegisterHandler {
|
||||
String hostIp = headers.get(HeadersEnum.HOST_IP.getKey());
|
||||
Integer hostPort = headers.getInt(HeadersEnum.HOST_PORT.getKey());
|
||||
String groupName = headers.get(HeadersEnum.GROUP_NAME.getKey());
|
||||
String contextPath = headers.get(HeadersEnum.CONTEXT_PATH.getKey());
|
||||
|
||||
LocalDateTime endTime = LocalDateTime.now().plusSeconds(30);
|
||||
ServerNode serverNode = new ServerNode();
|
||||
@ -56,6 +57,7 @@ public class ClientRegisterHandler {
|
||||
serverNode.setHostIp(hostIp);
|
||||
serverNode.setExpireAt(endTime);
|
||||
serverNode.setCreateDt(LocalDateTime.now());
|
||||
serverNode.setContextPath(contextPath);
|
||||
serverNode.setHostId(hostId);
|
||||
|
||||
try {
|
||||
|
@ -9,25 +9,27 @@
|
||||
<result column="host_port" jdbcType="INTEGER" property="hostPort" />
|
||||
<result column="expire_at" jdbcType="TIMESTAMP" property="expireAt" />
|
||||
<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="update_dt" jdbcType="TIMESTAMP" property="updateDt" />
|
||||
</resultMap>
|
||||
<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>
|
||||
<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,
|
||||
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},
|
||||
#{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
|
||||
host_id = values(`host_id`),
|
||||
host_ip = values(`host_ip`),
|
||||
host_port = values(`host_port`),
|
||||
expire_at = values(`expire_at`),
|
||||
node_type = values(`node_type`),
|
||||
create_dt = values(`create_dt`)
|
||||
create_dt = values(`create_dt`),
|
||||
context_path = values(`context_path`)
|
||||
</insert>
|
||||
<delete id="deleteByExpireAt">
|
||||
delete from server_node
|
||||
|
Loading…
Reference in New Issue
Block a user