Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

游戏对外服 netty 业务编排钩子接口 #28

Closed
iohao opened this issue Dec 5, 2022 · 0 comments
Closed

游戏对外服 netty 业务编排钩子接口 #28

iohao opened this issue Dec 5, 2022 · 0 comments
Assignees
Labels
使用技巧 使用技巧 可扩展 可扩展

Comments

@iohao
Copy link
Owner

iohao commented Dec 5, 2022

新增 ChannelPipelineHook netty 业务编排的处理器钩子接口,用于游戏对外服。

ExternalServerBuilder 新增 channelPipelineHook ,用于自定义 netty 业务编排的处理器。

废弃标记 ExternalServerBuilder.channelHandlerProcessors 属性及其相关地方为过期,由 ChannelPipelineHook 来代替,使用示例如下。

使用示例代码

public class ExternalServerBuilderApplication {
    public static void main(String[] args) {
        // netty ChannelHandler 编排
        var myChannelPipelineHook = new ChannelPipelineHook() {
            @Override
            public void initChannelPipeline(ChannelPipeline pipeline) {
                pipeline.addLast("ExternalBizHandler", new ExternalBizHandler());

                // pipeline.addFirst("ssl", ssl)
            }
        };

        // 游戏对外服构建器
        ExternalServerBuilder builder = ExternalServer.newBuilder(10100);
        builder.channelPipelineHook(myChannelPipelineHook);
    }
}

通常情况下,这样的编排方式也会更加清晰,因为代码统一在这里做编排了。

开发者在自定义业务编排时,可以通过这个钩子接口,比如添加一个 SSL。

注意事项:在调用 hook 前,会经过 ExternalChannelInitializerCallback.initChannelPipeline(SocketChannel) 。
ExternalChannelInitializerCallback 接口的实现类有

  1. ExternalChannelInitializerCallbackWebsocket
  2. ExternalChannelInitializerCallbackTcp

这些实现类中,会给 ChannelPipeline 添加上一些默认的处理器,通常是编解码相关的。

@iohao iohao changed the title 游戏对外服 netty 编排业务钩子接口 游戏对外服 netty 业务编排钩子接口 Dec 6, 2022
@iohao iohao added the 使用技巧 使用技巧 label Dec 6, 2022
iohao added a commit that referenced this issue Dec 6, 2022
(#28)
ExternalServerBuilder 新增 channelPipelineHook ,用于自定义 netty 业务编排的处理器。

标记 ExternalServerBuilder.channelHandlerProcessors 属性及其相关地方为过期,由 ChannelPipelineHook 来代替,使用示例如下。
iohao added a commit that referenced this issue Dec 6, 2022
@iohao iohao closed this as completed Dec 6, 2022
@iohao iohao self-assigned this Feb 1, 2023
@iohao iohao added the 可扩展 可扩展 label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
使用技巧 使用技巧 可扩展 可扩展
Projects
None yet
Development

No branches or pull requests

1 participant