[fix] 添加服务端ID

This commit is contained in:
wujiawei
2025-06-11 10:09:28 +08:00
parent c34f1239d8
commit 51b603a6c5
16 changed files with 100 additions and 42 deletions

View File

@ -1,14 +1,12 @@
package org.framework.lazy.cloud.network.heartbeat.client.application.command.lazy.netty.server.properties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import java.lang.String;
import java.time.LocalDateTime;
import java.lang.Integer;
/**
* describe 服务端配置信息
*
@ -21,7 +19,11 @@ import java.lang.Integer;
@Schema(title = "lazy_netty_server_properties_query_List_command",description = "服务端配置信息")
public class LazyNettyServerPropertiesQueryListCommand {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -5,6 +5,7 @@ import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.wu.framework.core.NormalUsedString;
import java.lang.String;
import java.time.LocalDateTime;
@ -22,6 +23,11 @@ import java.lang.Integer;
public class LazyNettyServerPropertiesQueryOneCommand {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -5,6 +5,7 @@ import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.wu.framework.core.NormalUsedString;
import java.lang.String;
import java.time.LocalDateTime;
@ -22,6 +23,11 @@ import java.lang.Integer;
public class LazyNettyServerPropertiesRemoveCommand {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -5,6 +5,7 @@ import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.wu.framework.core.NormalUsedString;
import java.lang.String;
import java.time.LocalDateTime;
@ -22,6 +23,11 @@ import java.lang.Integer;
public class LazyNettyServerPropertiesStoryCommand {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -5,6 +5,7 @@ import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.wu.framework.core.NormalUsedString;
import java.lang.String;
import java.time.LocalDateTime;
@ -21,6 +22,11 @@ import java.lang.Integer;
@Schema(title = "lazy_netty_server_properties_update_command",description = "服务端配置信息")
public class LazyNettyServerPropertiesUpdateCommand {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
private String serverId;
/**
*

View File

@ -1,14 +1,12 @@
package org.framework.lazy.cloud.network.heartbeat.client.application.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import java.lang.String;
import java.time.LocalDateTime;
import java.lang.Integer;
/**
* describe 服务端配置信息
*
@ -22,6 +20,11 @@ import java.lang.Integer;
public class LazyNettyServerPropertiesDTO {
/**
* 命名空间
*/
@Schema(description = "命名空间", name = "serverId", example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -17,7 +17,6 @@ import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.udp.sock
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;
@ -142,7 +141,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
@Override
public Result<List<LazyNettyServerPropertiesDTO>> findList(LazyNettyServerPropertiesQueryListCommand lazyNettyServerPropertiesQueryListCommand) {
LazyNettyServerProperties lazyNettyServerProperties = LazyNettyServerPropertiesDTOAssembler.INSTANCE.toLazyNettyServerProperties(lazyNettyServerPropertiesQueryListCommand);
return lazyNettyServerPropertiesRepository.findList(lazyNettyServerProperties).convert(lazyNettyServerPropertiess -> lazyNettyServerPropertiess.stream().map(LazyNettyServerPropertiesDTOAssembler.INSTANCE::fromLazyNettyServerProperties).collect(Collectors.toList()));
return lazyNettyServerPropertiesRepository.findList(lazyNettyServerProperties).convert(lazyNettyServerPropertiesList -> lazyNettyServerPropertiesList.stream().map(LazyNettyServerPropertiesDTOAssembler.INSTANCE::fromLazyNettyServerProperties).collect(Collectors.toList()));
}
/**
@ -186,6 +185,7 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
public void starterOneClientSocket(LazyNettyServerProperties lazyNettyServerProperties) {
boolean enabled = nettyClientProperties.isEnabled();
if (enabled) {
String serverId = lazyNettyServerProperties.getServerId();
String inetHost = lazyNettyServerProperties.getInetHost();
Integer inetPort = lazyNettyServerProperties.getInetPort();
String clientId = lazyNettyServerProperties.getClientId();
@ -196,12 +196,12 @@ public class LazyNettyServerPropertiesApplicationImpl implements LazyNettyServer
if (ProtocolType.TCP.equals(protocolType)) {
nettyClientSocket = new
NettyTcpClientSocket(inetHost, inetPort, clientId,
NormalUsedString.DEFAULT, appKey, appSecret,
serverId, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList);
} else if (ProtocolType.UDP.equals(protocolType)) {
nettyClientSocket = new
NettyUdpClientSocket(inetHost, inetPort, clientId,
NormalUsedString.DEFAULT, appKey, appSecret,
serverId, appKey, appSecret,
clientChangeEvent, handleChannelTypeAdvancedList);
} else {
nettyClientSocket = null;

View File

@ -4,6 +4,7 @@ import lombok.Data;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.wu.framework.core.NormalUsedString;
/**
* netty 客户服务端地址配置属性
@ -13,6 +14,11 @@ import org.springframework.context.annotation.Configuration;
@Data
public class NettyClientProperties {
public static final String PREFIX = "spring.lazy.netty.client";
/**
* 命名空间
*/
private String serverId= NormalUsedString.DEFAULT;
/**
* 服务端地址 如127.0.0.1
*/

View File

@ -26,7 +26,9 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
private final LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication;
public NettyClientSocketApplicationListener(NettyClientProperties nettyClientProperties, LazyLambdaStream lazyLambdaStream, LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
public NettyClientSocketApplicationListener(NettyClientProperties nettyClientProperties,
LazyLambdaStream lazyLambdaStream,
LazyNettyServerPropertiesApplication lazyNettyServerPropertiesApplication) {
this.nettyClientProperties = nettyClientProperties;
this.lazyLambdaStream = lazyLambdaStream;
this.lazyNettyServerPropertiesApplication = lazyNettyServerPropertiesApplication;
@ -44,12 +46,14 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
String appKey = nettyClientProperties.getAppKey();
String appSecret = nettyClientProperties.getAppSecret();
ProtocolType protocolType = nettyClientProperties.getProtocolType();
String serverId = nettyClientProperties.getServerId();
if (Objects.isNull(clientId) ||
Objects.isNull(inetHost)) {
log.warn("配置信息为空,请通过页面添加配置信息:{}", nettyClientProperties);
return;
}
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = new LazyNettyServerPropertiesDO();
lazyNettyServerPropertiesDO.setServerId(serverId);
lazyNettyServerPropertiesDO.setClientId(clientId);
lazyNettyServerPropertiesDO.setInetHost(inetHost);
lazyNettyServerPropertiesDO.setInetPort(inetPort);
@ -62,6 +66,7 @@ public class NettyClientSocketApplicationListener implements ApplicationListener
// 根据服务端端口、port 唯一性验证
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)

View File

@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.wu.framework.core.NormalUsedString;
import java.time.LocalDateTime;
/**
@ -21,6 +22,11 @@ import java.time.LocalDateTime;
public class LazyNettyServerProperties {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="namespace",example = "")
private String serverId;
/**
*
* 客户身份ID

View File

@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.client.config.PropertiesType;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.enums.ProtocolType;
import org.wu.framework.core.NormalUsedString;
import org.wu.framework.lazy.orm.core.stereotype.LazyTable;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableField;
import org.wu.framework.lazy.orm.core.stereotype.LazyTableFieldId;
@ -25,6 +26,12 @@ import java.time.LocalDateTime;
@Schema(title = "lazy_netty_server_properties",description = "服务端配置信息")
public class LazyNettyServerPropertiesDO {
/**
* 命名空间
*/
@Schema(description ="命名空间",name ="serverId",example = "")
@LazyTableFieldUnique(name="server_id",comment="命名空间",columnType="varchar(25)",defaultValue = "DEFAULT")
private String serverId;
/**
*
@ -38,7 +45,7 @@ public class LazyNettyServerPropertiesDO {
* 客户身份ID
*/
@Schema(description ="客户身份ID",name ="clientId",example = "")
@LazyTableFieldUnique(name="client_id",comment="客户身份ID",columnType="varchar(255)")
@LazyTableFieldUnique(name="client_id",comment="客户身份ID",columnType="varchar(25)")
private String clientId;
/**
@ -63,7 +70,7 @@ public class LazyNettyServerPropertiesDO {
* 服务端host
*/
@Schema(description ="服务端host",name ="inetHost",example = "")
@LazyTableFieldUnique(name="inet_host",comment="服务端host",columnType="varchar(255)")
@LazyTableFieldUnique(name="inet_host",comment="服务端host",columnType="varchar(25)")
private String inetHost;
/**

View File

@ -1,22 +1,19 @@
package org.framework.lazy.cloud.network.heartbeat.client.infrastructure.persistence;
import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerProperties;
import org.framework.lazy.cloud.network.heartbeat.client.domain.model.lazy.netty.server.properties.LazyNettyServerPropertiesRepository;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.converter.LazyNettyServerPropertiesConverter;
import org.framework.lazy.cloud.network.heartbeat.client.infrastructure.entity.LazyNettyServerPropertiesDO;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import java.util.stream.Collectors;
/**
* describe 服务端配置信息
@ -43,6 +40,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
@Override
public Result<LazyNettyServerProperties> story(LazyNettyServerProperties lazyNettyServerProperties) {
LazyNettyServerPropertiesDO lazyNettyServerPropertiesDO = LazyNettyServerPropertiesConverter.INSTANCE.fromLazyNettyServerProperties(lazyNettyServerProperties);
String serverId = lazyNettyServerPropertiesDO.getServerId();
String inetHost = lazyNettyServerPropertiesDO.getInetHost();
Integer inetPort = lazyNettyServerPropertiesDO.getInetPort();
String clientId = lazyNettyServerPropertiesDO.getClientId();
@ -50,6 +48,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
// 查询 ip、端口、客户端
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)
@ -57,6 +56,7 @@ public class LazyNettyServerPropertiesRepositoryImpl implements LazyNettyServerP
if (exists) {
// 更新
lazyLambdaStream.update(lazyNettyServerPropertiesDO, LazyWrappers.<LazyNettyServerPropertiesDO>lambdaWrapper()
.eq(LazyNettyServerPropertiesDO::getServerId, serverId)
.eq(LazyNettyServerPropertiesDO::getInetHost, inetHost)
.eq(LazyNettyServerPropertiesDO::getInetPort, inetPort)
.eq(LazyNettyServerPropertiesDO::getClientId, clientId)

View File

@ -10,11 +10,11 @@ import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.NettyClientSocket;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.event.ClientChangeEvent;
import org.framework.lazy.cloud.network.heartbeat.client.netty.permeate.tcp.filter.NettyTcpClientFilter;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.NettyServerContext;
import org.framework.lazy.cloud.network.heartbeat.common.adapter.ChannelTypeAdapter;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.HandleChannelTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.constant.TcpMessageType;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import java.net.InetAddress;
@ -88,7 +88,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 1024 * 1024 * 2))
.handler(new NettyTcpClientFilter(new ChannelTypeAdapter(handleChannelTypeAdvancedList), this))
;
log.info("use clientId:{} connect to server IP:{},server port :{}", clientId, inetHost, inetPort);
log.info("use clientId:{} connect to server serverId:{}, IP:{},server port :{}", clientId, serverId, inetHost, inetPort);
ChannelFuture future = bootstrap.connect(inetHost, inetPort);
// 客户端连接服务端的channel
Channel serviceChannel = future.channel();
@ -96,7 +96,7 @@ public class NettyTcpClientSocket implements NettyClientSocket {
future.addListener((ChannelFutureListener) futureListener -> {
if (futureListener.isSuccess()) {
log.info("clientId:{},connect to server IP:{},server port :{} isSuccess ", clientId, inetHost, inetPort);
log.info("clientId:{},connect to serverId:{}, server IP:{},server port :{} isSuccess ", clientId, serverId, inetHost, inetPort);
// 告诉服务端这条连接是client的连接
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(TcpMessageType.TCP_REPORT_CLIENT_CONNECT_SUCCESS);

View File

@ -5,7 +5,7 @@
<link rel="icon" href="./favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Java 使用 Lazy ORM 网络穿透客户端!</title>
<script type="module" crossorigin src="./assets/index-DjZ671Nk.js"></script>
<script type="module" crossorigin src="./assets/index-Dx8CuNMY.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BEQZ9T9z.css">
</head>
<body>

View File

@ -4,15 +4,20 @@ spring:
client:
# inet-host: 124.222.48.62
# inet-port: 30676
# inet-host: 124.222.152.160
# inet-port: 30560
inet-host: 127.0.0.1
inet-port: 7001
inet-host: 124.222.152.160
inet-port: 30560
server-id: tencent
# inet-host: 192.168.15.121
# inet-port: 7001
# server-id: win
# inet-host: 127.0.0.1
# inet-port: 7001
inet-path: wu-lazy-cloud-heartbeat-server
client-id: socks-local-proxy # 客户端ID
app-key: a4bf4415-25aa-4007-914b-31ec77d1292f
app-secret: 88e6d827-12e7-4a5d-93e0-92c04c2414bc
protocol-type: tcp
# inet-host: 124.222.48.62 # 服务端地址
# inet-port: 30676 #服务端端口
# # inet-path: wu-lazy-cloud-heartbeat-server