I'm trying to use the FeignClient to send HTTP requests to target service which were registered in Nacos.
The target service have several instances grouped by different versions and self-defined metadata.
I want to add the version and metadata information corresponding to the selected instance to the request header,
At present, I know that the logic is written in AbstractLoadBalancerAwareClient#executeWithLoadBalancer,
public T executeWithLoadBalancer(final S request, final IClientConfig requestConfig) throws ClientException {
...
public Observable<T> call(Server server) {
URI finalUri = reconstructURIWithServer(server, request.getUri());
S requestForServer = (S) request.replaceUri(finalUri);
try {
return Observable.just(AbstractLoadBalancerAwareClient.this.execute(requestForServer, requestConfig));
}
catch (Exception e) {
return Observable.error(e);
}
}
...
While, after the service is selected, there are no opportunity to append the request header according to the service instance.
Now, I end up re-writing AbstractLoadBalancerAwareClient#executeWithLoadBalancer. I wonder if there is any other simple way to do this
spring cloud version:Hoxton.SR8
Comment From: OlgaMaciaszek
Hi @chengaofeng, the Ribbon integration is under maintenance, so we do not add any enhancements there anymore. The suggested replacement is Spring Cloud LoadBalancer, which is available in SC OpenFeign via FeignBlockingLoadBalancerClient. It provides a hints mechanism in 2020.0.0.1 release train, but I'm not sure if that's going to be helpful in your usecase. Alternatively, what you could do at this point is override that client, but I'm thinking we might extract this into a separate method that could be overridden - would that be helpful?
Comment From: chengaofeng
@OlgaMaciaszek Thank you for the reply. It would be more appropriate to extract the creation request into a separate method, And I will try Spring Cloud LoadBalancer some time. For now , You are free to close this issue.
Comment From: OlgaMaciaszek
I'm going to extract that method for the Spring Cloud LoadBalancer within this issue already.