spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Improve ReactiveLoadBalancerClientFilter implementation so that we can pass attribute to ReactiveLoadBalancer

Open liubao68 opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. I am implementing a custom ReactiveLoadBalancer which depends on attributes from request. e.g.

public Mono<Response<ServiceInstance>> choose(Request request) {
   Object attribute = getAttribute(request);
   doStringSometingWithAttribute
   ...
}

However ReactiveLoadBalancerClientFilter (line 116,117) construct Request using

		DefaultRequest<RequestDataContext> lbRequest = new DefaultRequest<>(
				new RequestDataContext(new RequestData(exchange.getRequest()), getHint(serviceId)));

and do not pass attributes from ServerWebExchange and we can not get attribute in custom ReactiveLoadBalancer implementation.

Describe the solution you'd like Improve the code using RequestData constructor:

	public RequestData(HttpMethod httpMethod, URI url, HttpHeaders headers, MultiValueMap<String, String> cookies,
			Map<String, Object> attributes)

Describe alternatives you've considered NA

Additional context This feature is quite useful when implement features like loadbalancer with retry which depends on the status of last execution.

liubao68 avatar Sep 03 '22 08:09 liubao68