Reputation: 1067
Netty Connection Pool
I would like to know which options or how to implement a client connection pool in netty.
Upvotes: 0
Views: 4765
Reputation: 16056
I have not implemented this, so this is just some educated guess-work, but I would consider combining the following:
The generic object pooling would support you in creating a connection cache, with the remote socket address as the key, so you might issue a request like:
pool.borrowObject("www.google.com:80");
Not sure about the channel group, except that it is a good way to issue directives against all the contained channels in one go (e.g. close()), so it might be useful to have the pool's PooledObjectFactory always insert all it's created channels into a channel group as well. It is self maintaining since the channels are ejected from the group when they close.
Commons Pooling has been super useful for me in many situations, though mostly when I am attempting to pool and reuse expensive-to-create resources. Is this how you view your client connections ?
Update Aug 30, 2017:
The preferred way to do this in Netty 4.x is to use a ChannelPool. Netty 4.0: ChannelPool Netty 4.1: ChannelPool
Upvotes: 1