增加netty版本

This commit is contained in:
2023-08-20 22:19:23 +08:00
parent a53475fef8
commit eaccee2a9b
41 changed files with 2660 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package com;
import com.sv.netty.config.SpringContextHolder;
import com.sv.netty.netty.BootService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -25,6 +26,9 @@ public class WeiXinApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(WeiXinApplication.class, args);
SpringContextHolder.setContext(context);
//启动netty
BootService bootService = (BootService) context.getBean("bootService");
bootService.run();
}
}

View File

@@ -22,7 +22,7 @@ import java.util.concurrent.Executors;
* @Author peakren
* @Date 03/05/2017 6:18 PM
*/
//@Component
@Component
public class BootService {
private Logger logger = LoggerFactory.getLogger(BootService.class);
@@ -40,25 +40,25 @@ public class BootService {
/**
* 下面几个是由spring注入
*/
// @Value("${netty.port}")
@Value("${netty.port}")
private int port;
// @Value("${so.keepalive}")
@Value("${so.keepalive}")
private Boolean keepalive;
// @Value("${so.backlog}")
@Value("${so.backlog}")
private int backlog;
// @Value("${tcp_nodelay}")
@Value("${tcp_nodelay}")
private boolean nodelay;
// @Value("${so.reuseaddr}")
@Value("${so.reuseaddr}")
private boolean reuseaddr;
// @Value("${boss.thread.count}")
@Value("${boss.thread.count}")
private int bossCount;
// @Value("${worker.thread.count}")
@Value("${worker.thread.count}")
private int workerCount;
private Map<ChannelOption, Object> channelOptions;

View File

@@ -20,7 +20,7 @@ import java.util.Set;
* @author ranfi
*/
//@ChannelHandler.Sharable
@ChannelHandler.Sharable
public class ServerHandler extends SimpleChannelInboundHandler<String> {
private static Logger logger = LoggerFactory.getLogger(ServerHandler.class);
@@ -125,8 +125,8 @@ public class ServerHandler extends SimpleChannelInboundHandler<String> {
// ctx.channel().close();
// }
// }
Set<String> conns = messageService.countConnection();
logger.info("count connected device ! the count is " + conns.size() + " and they are + [" + conns.toString() + "]" );
Set<String> connections = messageService.countConnection();
logger.info("count connected device ! the count is " + connections.size() + " and they are + [" + connections.toString() + "]" );
}
}

View File

@@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
* @Author peakren
* @Date 09/05/2017 5:19 PM
*/
//@Component
@Component
public class ServerProtocolInitializer extends ChannelInitializer<SocketChannel> {
private final int IDLE_TIME = 120; //连接检测空闲时间

View File

@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
* @Author peakren
* @Date 08/05/2017 10:43 PM
*/
//@Service("messageService")
@Service("messageService")
public class AppMessageHandlerAdapter implements MessageService {
private Logger logger = LoggerFactory.getLogger(AppMessageHandlerAdapter.class);