ILoadBalancer does not support this case when the service instance's hostname is not equal to ip
Is your feature request related to a problem? Please describe.
When some service instance use special hostname rather than ip.
curl "http://127.0.0.1/xxx" -H "Host: bar.com"
Describe the solution you'd like
IServiceInstance.Uri should return scheme://ip:port/
-public virtual async Task<Uri> ResolveServiceInstanceAsync(Uri request)
+public virtual async Task ResolveServiceInstanceAsync(HttpRequestMessage request)
{
var resolvedUri = availableServiceInstances[_random.Next(availableServiceInstances.Count)].Uri;
- return new Uri(resolvedUri, request.PathAndQuery);
+ equest.RequestUri = new Uri(resolvedUri, request.RequestUri.PathAndQuery);
+ request.Headers.Host = resolvedUri.Host;
}
Describe alternatives you've considered
The hostname resolution result may be different with the ip, so the specified service instance cannot be accessed
Additional context
Can you provide a sample app that illustrates this problem...
Thanks
{
"eureka:instance": {
"instance": {
//"preferIpAddress": true,
"hostName": "bar.com",
"ipAddress": "127.0.0.1",
"port": 80
}
}
}
If preferIpAddress is true, instance uri is http://127.0.0.1. if preferIpAddress is false , instance uri is http://bar.com. When my site depoly in iis, binding with *:9054:bar.com, and bar.com resolved to multiple ips, the right way is
curl "http://127.0.0.1/xxx" -H "Host: bar.com"
We will addressing with our Eureka updates in Epic #493
This may not be possible with the data provided by service registrations
This reads to me as a case where the app registering should set Eureka:Instance:RegistrationMethod to HostName so that the hostname will be used for the Uri and the IP address can be resolved via DNS. Please let us know if there is still a need to have both IP address and hostname specified