ojas
ojas

Reputation: 2210

Netty: configure timeout for channel read per channel

I am using Netty framework and implemented client and server. I am making many connections as high as 1000. I want to configure timeout values in multiple places. Some of them i am able to figure out. So, here's the netty behavior of my netty implementation:
1. Many async connections starts from client with the timeout(configured using ChannelOption.CONNECT_TIMEOUT_MILLIS).
2. Those client connections which are able to connect sends HTTP request using channelActive and receives response using channelRead0.

Problem - I want to place timeout value between sending the request and receiving the data for a particular channel.
I read the netty documentation and come up with two solutions:
1. https://netty.io/4.0/api/io/netty/channel/ChannelConfig.html#setConnectTimeoutMillis-int-
2. https://netty.io/4.0/api/io/netty/handler/timeout/ReadTimeoutHandler.html

I am confused which option to choose and which one is better or is there any other option.

Upvotes: 1

Views: 1905

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23567

You will need to set multiple limits (most likely). As you already found out you may want to set a connect timeout via setConnectTimeoutMillis but also have a ChannelDuplexHandler that will ensure you receive the response to a request in the expected time. You may also want to have a look at IdleStateHandler which will allow to fire events through the ChannelPipeline if the Channel idles for too long.

Upvotes: 1

Related Questions