Send multiple asynchonous requests on a Netty client

前端 未结 1 1270
无人共我
无人共我 2021-01-05 17:58

first, let me explain the context :

I\'ve got to create a client which will send many HTTP requests to download images. These requests has to be asynchronous because

相关标签:
1条回答
  • 2021-01-05 18:35

    The problem is that you're sharing a single HttpClientCodec between all your channels. The default pipeline specified in the bootstrap is cloned for all channels, so each channel sees the same instance of each handler. The http codecs are stateful so you're seeing the effects of different responses getting mixed together.

    The easiest solution is to pass a ChannelPipelineFactory to the bootstrap. This will be called for each new channel and you can create a pipeline with new instances of HttpClientCodec. There's nothing to stop you using the same instance of TileClientHandler for every pipeline you create if that is how it's intended to work.

    I'm curious though. Given that you're making each request concurrently, wouldn't it be easier to just add HttpChunkAggregator upstream of HttpClientCodec and let Netty aggregate all the chunks into a single HttpResponse. Then you just grab the reassembled content from there?

    0 讨论(0)
提交回复
热议问题