HTTP client unable to specify which IP to bind to, what should I do?
weiyouren opened this issue · comments
Expected Behavior
bind network interface to http client
Actual Behavior
i wan to bind network interface to http client, but it not work
Steps to Reproduce
public static WebClient getWebClient(String name) {
var provider = ConnectionProvider
.builder(name)
.maxConnections(4096)
.pendingAcquireMaxCount(4096)
//.pendingAcquireTimeout(Duration.ofSeconds(60))
.maxIdleTime(Duration.ofSeconds(30))
//.maxLifeTime(Duration.ofMinutes(30))
.evictInBackground(Duration.ofSeconds(10))
.lifo()
.build();
var connector = new ReactorClientHttpConnector(HttpClient.create(provider)
.compress(true)
.bindAddress(() -> new InetSocketAddress("192.168.0.2", 0))//not working,why?
.protocol(HttpProtocol.H2)
.secure()
.keepAlive(true));
return WebClient.builder()
.clientConnector(connector)
.baseUrl(BASE_URL)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
Possible Solution
Your Environment
- Reactor version(s) used: 1.1.10
- Other relevant libraries versions (eg.
netty
, ...): - JVM version (
java -version
):java 17.0.8 2023-07-18 LTS - OS and version (eg.
uname -a
):centos 7 x64
I have two network cards with different IP addresses,192.168.0.2 it's an example
@weiyouren Please provide the logs with the problem. I tried to bind the client, where the address was specific for my local machine, and there were no issues with binding.
@weiyouren In addition to the configuration that you have can we also specify bindAddress for Host Name resolution like this:
// bindAddress for the client requests
.bindAddress(() -> new InetSocketAddress("192.168.0.2", 0))//not working,why?
// bindAddress for Host Name resolution
.resolver(spec -> spec.bindAddressSupplier(() -> new InetSocketAddress("192.168.0.2", 0)))
Can you also provide tcp dump?
@weiyouren Can you provide also logs from the execution? You need to enable wiretap(true)
on the HttpClient
and also to enable logging for reactor.netty
logger.
I cannot reproduce this issue with my setup.
@weiyouren I'm closing this with cannot reproduce
. We can reopen the issue when you are able to provide the requested information.