Java 具有不同服务路径的多个通道

Java 具有不同服务路径的多个通道,java,websocket,netty,Java,Websocket,Netty,[我正在使用Netty Websokcet] 我有一个用例,不同的服务路径应该连接到同一个端口。我尝试了很多不同的方法,我无法完成工作的原因是 在ServerBootstrap类中,ChannelHandler只有一个位置,因此我无法在ServerBootstrap中添加具有不同服务路径的多个子处理程序 在ServerBootstrap类中,无法创建多个组 这就是我的init频道的样子 @Override protected void initChannel(SocketChannel so

[我正在使用Netty Websokcet]

我有一个用例,不同的服务路径应该连接到同一个端口。我尝试了很多不同的方法,我无法完成工作的原因是

  • ServerBootstrap
    类中,
    ChannelHandler
    只有一个位置,因此我无法在
    ServerBootstrap
    中添加具有不同服务路径的多个子处理程序
  • ServerBootstrap
    类中,无法创建多个组
这就是我的init频道的样子

@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    logger.debug(1, "Initializing the SocketChannel : {}", socketChannel.id());

    socketChannel.pipeline().addLast(
            new HttpRequestDecoder(),
            new HttpObjectAggregator(maxPayloadSize),
            new HttpResponseEncoder(),
            new IdleStateHandler(0, 0, listenerConfig.getSocketTimeout(),
                    TimeUnit.SECONDS),
            new WebSocketServerProtocolHandler(ingressConfig.getURI().getPath()), // (A)
            new WebSocketServerCompressionHandler(),
            new WebSocketIO(listenerConfig, manager), // a handler
            new WebSocketMessageListener(messageReceiver, manager) // a handler
    );

    logger.debug(2, "Successfully initialized the Socket Channel : {}", socketChannel.id());
}
此代码行(A)使用给定的服务路径注册处理程序(服务路径为
ingresconfig.getURI().getPath()

有人能给我建议一个方法吗

 int maxPayloadSize = listenerConfig.getMaxPayloadSize();
    try {
        bossGroup = new NioEventLoopGroup(listenerConfig.getBossThreadCount());
        workerGroup = new NioEventLoopGroup(listenerConfig.getWorkerThreadCount());

        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new WebSocketListenerInitializer(messageReceiver, maxPayloadSize, listenerConfig,
                        ingressConfig))
                .option(ChannelOption.SO_BACKLOG, 128)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        ChannelFuture channelFuture = bootstrap.bind(port);
        channelFuture.sync();
        channel = channelFuture.channel();

        if (channelFuture.isSuccess()) {
            logger.info(1, "WebSocket listener started on port : {} successfully", port);
        } else {
            logger.error(2, "Failed to start WebSocket server on port : {}", port,
                    channelFuture.cause());
            throw new TransportException("Failed to start WebSocket server", channelFuture.cause());
        }

    } catch (InterruptedException ex) {
        logger.error(1, "Interrupted Exception from : {}", WebSocketListener.class);
        throw new TransportException("Interrupted Exception", ex);
    }