mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2025-12-26 04:47:53 +08:00
[优化]避免多次创建NettyWebSocketServerHandler
This commit is contained in:
parent
a1a1c4061b
commit
d78624caa7
@ -27,6 +27,7 @@ import javax.annotation.PreDestroy;
|
||||
@Configuration
|
||||
public class NettyWebSocketServer {
|
||||
public static final int WEB_SOCKET_PORT = 8090;
|
||||
public static final NettyWebSocketServerHandler NETTY_WEB_SOCKET_SERVER_HANDLER = new NettyWebSocketServerHandler();
|
||||
// 创建线程池执行器
|
||||
private EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
private EventLoopGroup workerGroup = new NioEventLoopGroup(NettyRuntime.availableProcessors());
|
||||
@ -90,7 +91,7 @@ public class NettyWebSocketServer {
|
||||
*/
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler("/"));
|
||||
// 自定义handler ,处理业务逻辑
|
||||
pipeline.addLast(new NettyWebSocketServerHandler());
|
||||
pipeline.addLast(NETTY_WEB_SOCKET_SERVER_HANDLER);
|
||||
}
|
||||
});
|
||||
// 启动服务器,监听端口,阻塞直到启动成功
|
||||
|
||||
@ -7,6 +7,7 @@ import com.abin.mallchat.common.user.domain.enums.WSReqTypeEnum;
|
||||
import com.abin.mallchat.common.user.domain.vo.request.ws.WSAuthorize;
|
||||
import com.abin.mallchat.common.user.domain.vo.request.ws.WSBaseReq;
|
||||
import com.abin.mallchat.common.user.service.WebSocketService;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
@ -17,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Sharable
|
||||
public class NettyWebSocketServerHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
|
||||
|
||||
private WebSocketService webSocketService;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user