带postgres的javanettytcp服务器查询无限期挂起

nzrxty8p  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(264)

我在netty上用tcp服务器编写spring引导应用程序。服务获取消息并检查postgres数据库中的行。问题是,在检查数据库中的记录时,服务挂起并停止处理来自tcp通道的其他消息。
配置:

@Bean
public void start() throws InterruptedException {
    log.info("Starting server at: {} ", tcpPort);
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

        ServerBootstrap b = new ServerBootstrap();
        b.group(workerGroup, bossGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(simpleTCPChannelInitializer)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(tcpPort).sync();
        if(f.isSuccess())
            log.info("Server started successfully");
        f.channel().closeFuture().sync();

}

通道初始化:

private final EventExecutorGroup sqlExecutorGroup = new DefaultEventExecutorGroup(16);

protected void initChannel(SocketChannel socketChannel) {
    socketChannel.pipeline().addLast(new StringEncoder());
    socketChannel.pipeline().addLast(new StringDecoder());
    socketChannel.pipeline().addLast(sqlExecutorGroup, simpleTCPChannelHandler);
}

数据库的定义和方法:

@Override
public void processMessage(String atmRequest) {
        log.info("Receive tcp atmRequest: {}", atmRequest);
        checkDeviceInDatabase(deviceUid);
        log.info("Receive power up command");
}

private void checkDeviceInDatabase(String deviceUid) {
    statusConnectRepository.findById(deviceUid).orElseThrow(()
            -> new DeviceNotFoundException("DeviceUid: " + deviceUid + " was not found in database"));
}

在checkdeviceindatabase(deviceuid)方法中,查询将永远挂起。有人遇到过这样的问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题