Skip to content

netty实现grpc代理的问题求指教 #1

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

Open
gm100861 opened this issue Mar 3, 2022 · 2 comments
Open

netty实现grpc代理的问题求指教 #1

gm100861 opened this issue Mar 3, 2022 · 2 comments

Comments

@gm100861
Copy link

gm100861 commented Mar 3, 2022

大佬你好,我最近在学习netty, 已经使用netty实现了一个HTTP代理.接下来准备做grpc的代理.grpc是基于HTTP2的, 有挺多东西.跟HTTP代理不一样,所以遇到了一些问题,也看了很多文章最终没能解决, 所以在netty的仓库下提了一个issue,也看到大佬回复了,但是按照你的回复我加了一个handler还是不能正常返回消息.所以想请大佬不再指点下,我应该怎么做.

netty issue link: netty/netty#12090

万分感谢,十分期待得到您的回复.

@coderbruis
Copy link
Owner

不是大佬,只是刚好也在研究Netty原理,所以尝试解答一下。有什么问题呢?我看程序不报错了。

@gm100861
Copy link
Author

gm100861 commented Mar 9, 2022

有几个疑问,想和你一起探讨一下! (代码我更新了一下, 地址: https://gitee.com/gm100861/netty-grpc-proxy)

  1. 为什么需要添加一个空的handler, 啥都不做,这是netty对HTTP支持有啥问题吗? 还是可以通过别的方法去掉这个空的handler
    CustHttp2ClientInit 类中
    @Override protected void initChannel(SocketChannel channel) throws Exception { Http2FrameCodec http2FrameCodec = Http2FrameCodecBuilder.forClient().build(); channel.pipeline().addLast(http2FrameCodec); channel.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG)); channel.pipeline().addLast(new GrpcClientHandler(http2HeadersFrame, dataFrame, outboundContext)); channel.pipeline().addLast(new Http2MultiplexHandler(new ChannelInboundHandlerAdapter())); }

3.在CustHttp2ServerHandler中67行,为什么需要一个Http2StreamChannelBootstrap, 不太明白这一段代码的意思.因为我这个是根据请求头做一个透明代理,所以我要把服务端的响应数据,再响应给客户端,现在我直接用代理的ctx响应, 发现客户端不能收到响应数据,是因为这一段代码影响的吗?是不是需要使用http2StreamChannel这个新创建的channel来做响应?

以上, 期待探讨!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants