Skip to content

Commit

Permalink
Merge pull request #133 from crossoverJie/jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie authored Jun 2, 2024
2 parents abc161e + 5c6b288 commit 3acb6e3
Show file tree
Hide file tree
Showing 48 changed files with 365 additions and 523 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [ ] Client use [picocli](https://picocli.info/) instead of springboot.
- [ ] Supports binary client(build with golang).
- [ ] Support integration testing.
- [ ] Integrate OpenTelemetry .
- [ ] Support single node startup(Contains no components).
- [ ] Third-party components support replacement(Redis/Zookeeper, etc.).
- [ ] Support web client(websocket).
Expand Down
20 changes: 4 additions & 16 deletions cim-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
<swagger.version>2.5.0</swagger.version>
<logback.version>1.2.3</logback.version>
</properties>


Expand All @@ -33,17 +32,12 @@
<artifactId>cim-common</artifactId>
</dependency>


<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -66,12 +60,6 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.crossoverjie.cim.client.config.AppConfiguration;
import com.crossoverjie.cim.client.init.CIMClientHandleInitializer;
import com.crossoverjie.cim.client.service.EchoService;
import com.crossoverjie.cim.client.service.MsgHandle;
import com.crossoverjie.cim.client.service.ReConnectManager;
import com.crossoverjie.cim.client.service.RouteRequest;
import com.crossoverjie.cim.client.service.impl.ClientInfo;
Expand All @@ -23,13 +22,14 @@
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

/**
* Function:
Expand All @@ -39,9 +39,9 @@
* @since JDK 1.8
*/
@Component
@Slf4j
public class CIMClient {

private final static Logger LOGGER = LoggerFactory.getLogger(CIMClient.class);

private EventLoopGroup group = new NioEventLoopGroup(0, new DefaultThreadFactory("cim-work"));

Expand All @@ -62,8 +62,6 @@ public class CIMClient {
@Autowired
private AppConfiguration configuration;

@Autowired
private MsgHandle msgHandle;

@Autowired
private ClientInfo clientInfo;
Expand Down Expand Up @@ -111,14 +109,14 @@ private void startClient(CIMServerResVO.ServerInfo cimServer) {
errorCount++;

if (errorCount >= configuration.getErrorCount()) {
LOGGER.error("连接失败次数达到上限[{}]次", errorCount);
msgHandle.shutdown();
log.error("连接失败次数达到上限[{}]次", errorCount);
// shutdownService.closeMsgHandle();
}
LOGGER.error("Connect fail!", e);
log.error("Connect fail!", e);
}
if (future.isSuccess()) {
echoService.echo("Start cim client success!");
LOGGER.info("启动 cim client 成功");
log.info("启动 cim client 成功");
}
channel = (SocketChannel) future.channel();
}
Expand All @@ -139,15 +137,15 @@ private CIMServerResVO.ServerInfo userLogin() {
clientInfo.saveServiceInfo(cimServer.getIp() + ":" + cimServer.getCimServerPort())
.saveUserInfo(userId, userName);

LOGGER.info("cimServer=[{}]", cimServer.toString());
log.info("cimServer=[{}]", cimServer.toString());
} catch (Exception e) {
errorCount++;

if (errorCount >= configuration.getErrorCount()) {
echoService.echo("The maximum number of reconnections has been reached[{}]times, close cim client!", errorCount);
msgHandle.shutdown();
// shutdownService.closeMsgHandle();
}
LOGGER.error("login fail", e);
log.error("login fail", e);
}
return cimServer;
}
Expand Down Expand Up @@ -177,7 +175,7 @@ public void sendStringMsg(String msg) {
message.writeBytes(msg.getBytes());
ChannelFuture future = channel.writeAndFlush(message);
future.addListener((ChannelFutureListener) channelFuture ->
LOGGER.info("客户端手动发消息成功={}", msg));
log.info("客户端手动发消息成功={}", msg));

}

Expand All @@ -197,7 +195,7 @@ public void sendGoogleProtocolMsg(GoogleProtocolVO googleProtocolVO) {

ChannelFuture future = channel.writeAndFlush(protocol);
future.addListener((ChannelFutureListener) channelFuture ->
LOGGER.info("客户端手动发送 Google Protocol 成功={}", googleProtocolVO.toString()));
log.info("客户端手动发送 Google Protocol 成功={}", googleProtocolVO.toString()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class AppConfiguration {
@Value("${cim.msg.logger.path}")
private String msgLoggerPath ;

@Value("${cim.clear.route.request.url}")
private String clearRouteUrl ;

@Value("${cim.heartbeat.time}")
private long heartBeatTime ;
Expand Down Expand Up @@ -65,13 +63,7 @@ public void setHeartBeatTime(long heartBeatTime) {
}


public String getClearRouteUrl() {
return clearRouteUrl;
}

public void setClearRouteUrl(String clearRouteUrl) {
this.clearRouteUrl = clearRouteUrl;
}

public int getErrorCount() {
return errorCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package com.crossoverjie.cim.client.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
/** 是否打开swagger **/
@ConditionalOnExpression("'${swagger.enable}' == 'true'")
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.crossoverjie.netty.action.client.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("sbc order api")
.description("sbc order api")
.termsOfServiceUrl("http://crossoverJie.top")
.contact("crossoverJie")
.version("1.0.0")
.build();
}
}
//package com.crossoverjie.cim.client.config;
//
//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
//
//
//@Configuration
//@EnableSwagger2
///** 是否打开swagger **/
//@ConditionalOnExpression("'${swagger.enable}' == 'true'")
//public class SwaggerConfig {
//
//
// @Bean
// public Docket createRestApi() {
// return new Docket(DocumentationType.SWAGGER_2)
// .apiInfo(apiInfo())
// .select()
// .apis(RequestHandlerSelectors.basePackage("com.crossoverjie.netty.action.client.controller"))
// .paths(PathSelectors.any())
// .build();
// }
//
// private ApiInfo apiInfo() {
// return new ApiInfoBuilder()
// .title("sbc order api")
// .description("sbc order api")
// .termsOfServiceUrl("http://crossoverJie.top")
// .contact("crossoverJie")
// .version("1.0.0")
// .build();
// }
//
//}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import com.crossoverjie.cim.client.vo.req.SendMsgReqVO;
import com.crossoverjie.cim.client.vo.req.StringReqVO;
import com.crossoverjie.cim.client.vo.res.SendMsgResVO;
import com.crossoverjie.cim.common.constant.Constants;
import com.crossoverjie.cim.common.enums.StatusEnum;
import com.crossoverjie.cim.common.res.BaseResponse;
import com.crossoverjie.cim.common.res.NULLBody;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -31,11 +28,6 @@
@RequestMapping("/")
public class IndexController {

/**
* 统计 service
*/
@Autowired
private CounterService counterService;

@Autowired
private CIMClient heartbeatClient ;
Expand All @@ -51,7 +43,7 @@ public class IndexController {
* @param stringReqVO
* @return
*/
@ApiOperation("客户端发送消息,字符串")
// @ApiOperation("客户端发送消息,字符串")
@RequestMapping(value = "sendStringMsg", method = RequestMethod.POST)
@ResponseBody
public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO){
Expand All @@ -61,8 +53,7 @@ public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO
heartbeatClient.sendStringMsg(stringReqVO.getMsg()) ;
}

// 利用 actuator 来自增
counterService.increment(Constants.COUNTER_CLIENT_PUSH_COUNT);
// TODO: 2024/5/30 metrics

SendMsgResVO sendMsgResVO = new SendMsgResVO() ;
sendMsgResVO.setMsg("OK") ;
Expand All @@ -76,7 +67,7 @@ public BaseResponse<NULLBody> sendStringMsg(@RequestBody StringReqVO stringReqVO
* @param googleProtocolVO
* @return
*/
@ApiOperation("向服务端发消息 Google ProtoBuf")
// @ApiOperation("向服务端发消息 Google ProtoBuf")
@RequestMapping(value = "sendProtoBufMsg", method = RequestMethod.POST)
@ResponseBody
public BaseResponse<NULLBody> sendProtoBufMsg(@RequestBody GoogleProtocolVO googleProtocolVO){
Expand All @@ -86,8 +77,7 @@ public BaseResponse<NULLBody> sendProtoBufMsg(@RequestBody GoogleProtocolVO goog
heartbeatClient.sendGoogleProtocolMsg(googleProtocolVO) ;
}

// 利用 actuator 来自增
counterService.increment(Constants.COUNTER_CLIENT_PUSH_COUNT);
// TODO: 2024/5/30 metrics

SendMsgResVO sendMsgResVO = new SendMsgResVO() ;
sendMsgResVO.setMsg("OK") ;
Expand All @@ -103,7 +93,7 @@ public BaseResponse<NULLBody> sendProtoBufMsg(@RequestBody GoogleProtocolVO goog
* @param sendMsgReqVO
* @return
*/
@ApiOperation("群发消息")
// @ApiOperation("群发消息")
@RequestMapping(value = "sendGroupMsg",method = RequestMethod.POST)
@ResponseBody
public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws Exception {
Expand All @@ -112,7 +102,7 @@ public BaseResponse sendGroupMsg(@RequestBody SendMsgReqVO sendMsgReqVO) throws
GroupReqVO groupReqVO = new GroupReqVO(sendMsgReqVO.getUserId(),sendMsgReqVO.getMsg()) ;
routeRequest.sendGroupMsg(groupReqVO) ;

counterService.increment(Constants.COUNTER_SERVER_PUSH_COUNT);
// TODO: 2024/5/30 metrics

res.setCode(StatusEnum.SUCCESS.getCode()) ;
res.setMessage(StatusEnum.SUCCESS.getMessage()) ;
Expand Down
Loading

0 comments on commit 3acb6e3

Please sign in to comment.