Reputation: 31
I have a machine which has five different IP-Addresses. Is it possible to tell Java which IP-address should be used for HTTP-Requests (during runtime and client-side)?
Example: First request -> first ip
Second request -> second ip ...
Kind of a rotating IP-config.
The library Netty is available too, but I'm not forced to use it.
Thanks in advance.
Upvotes: 3
Views: 162
Reputation: 4134
You are trying to do client-side HTTP load balancing. You can use Netflix Ribbon client library to get this done in a very configurable manner. Its based on Netty, and is very performant when dealing with large number of connections for the client. Check this example.
Upvotes: 0
Reputation: 8928
It is possible if you create your own sockets, as one of the Socket
constructors allows you to specify the local address as well as the remote address. You might have to construct your own HTTP request and parse the response, though.
As best I can tell, the HttpUrlConnection
class does not allow you to specify its local address, perhaps because it manages connections itself behind the scenes, so unfortunately it looks like you won't be able to take advantage of its HTTP and URL related convenience methods.
Upvotes: 1