我正在尝试使用netty来实现HTTP / 2客户端。 在这个例子中 (第93行),他们手动递增streamId并将其放入地图。 当响应到来时,它们会查找HttpConversionUtil.ExtensionHeaderNames.STREAM_ID标头参数,从而将响应与请求相关联。
我不喜欢自己增加streamId的想法。 我可以以某种方式获得id writeAndFlush将用于writeAndFlush请求吗?
此外,创建新流需要很多资源吗? 或者它只是一个标识符?
I'm trying to use netty to implement HTTP/2 client. In this example (line 93) they manually increment streamId and put it to the map. When response comes they look for HttpConversionUtil.ExtensionHeaderNames.STREAM_ID header parameter and thus associate the response with the request.
I don't like the idea of increasing streamId by myself. Can I somehow get the id netty's going to use to writeAndFlush the request?
Also, does it take much resources to create a new stream? Or is it just an identifier?
最满意答案
我很确定,此时你无法获得streamId生成和使用的streamId 。 另外,我不喜欢自己增加streamId的想法,但看起来可以使用当前的API来做到这一点。
我检查了Netty的来源并找到了下面的东西:
HttpToHttp2ConnectionHandler用于写入请求。 它有私有方法getStreamId ,它在write方法中用于获取currentStreamId值。 但我们没有任何访问此变量的权限。 getStreamId方法使用另一个名为incrementAndGetNextStreamId的方法。 所以,再次,我们只能增加并获得新的streamId值,但无法获得当前的值。这两个类都标有@UnstableApi注释,因此将来这种行为可能会发生变化。
这是一些相关的链接:
从Netty存储库稍微更新了HTTP 2客户端示例 。 HTTP / 2 Java客户端示例 。 为什么netty http2服务器总是使用奇数来表示streamId 。I'm pretty sure, at this moment you can't get streamId generated and used by Netty. Also, I don't like the idea of increasing streamId by myself too, but looks like it's okay to do this with current API.
I've checked Netty sources and found next things:
HttpToHttp2ConnectionHandler is used for writing requests. It has private method getStreamId which is used in write method for getting value of currentStreamId. But we doesn't have any access to this variable. getStreamId method uses another method called incrementAndGetNextStreamId. So, again, we can only increment and get new streamId value but can't get the current one.Both of these classes marked with annotation @UnstableApi, so maybe this behavior will be change in the future.
Here's some related links:
A little bit updated HTTP 2 client example from Netty repository. HTTP/2 Java Client Examples. Why netty http2 server always use odd number for streamId.更多推荐
发布评论