Skip to content

Add request header after Load Balance Instance selected #423

Closed
@chengaofeng

Description

@chengaofeng

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions