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

how to configuration spring aop with TraceLoadBalancerFeignClient ?

Open xinluke opened this issue 8 years ago • 4 comments

i using spring-cloud-sleuth in project, i want to do some thing after TraceLoadBalancerFeignClient.execute finish. so,i try configuration spring aspect,like that

@Around("execution (* org.springframework.cloud.sleuth.instrument.web.client.feign.TraceLoadBalancerFeignClient.execute(..))")
    public Object feignClientWasCalled(final ProceedingJoinPoint pjp) throws Throwable {
        Object[] args = pjp.getArgs();
        Request request = (Request) args[0];
        Request.Options options = (Request.Options) args[1];
        Object bean = pjp.getTarget();
        Object resp = pjp.proceed();
        
        //do some thing

            return resp;

but not work. if i want to do something after TraceLoadBalancerFeignClient.execute,what shoud i do?

xinluke avatar Mar 19 '18 15:03 xinluke

What do you want to do exactly?

marcingrzejszczak avatar Mar 19 '18 15:03 marcingrzejszczak

@marcingrzejszczak exactly, i hope when my feignClient Load balancer does not have available server for client ,try request to remote proxy url,so i want to add custom bussiness.

xinluke avatar Mar 19 '18 16:03 xinluke

TraceLoadBalancerFeignClient is an implementation detail. You shouldn't be touching that.

TLBFC is calling a delegate, so whichever LoadBalancerFeignClient delegate you had, it will get called by the TLBFC. You should define your logic in your implementation of a LoadBalancerFeignClient.

marcingrzejszczak avatar Mar 19 '18 16:03 marcingrzejszczak

i try define myLoadBalancerFeignClient extend of LoadBalancerFeignClient , and override the LBFC.execute, but not work; i debug the code, TraceFeignObjectWrapper.warp alway warp Client, if the Client instanceof LoadBalancerFeignClient,it will use client.getDelegate() to rebuild TraceLoadBalancerFeignClient,and myLoadBalancerFeignClient is useless and not work. the code of TraceFeignObjectWrapper

	Object wrap(Object bean) {
		if (bean instanceof Client && !(bean instanceof TraceFeignClient)) {
			if (bean instanceof LoadBalancerFeignClient && !(bean instanceof TraceLoadBalancerFeignClient)) {
				LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean);
				return new TraceLoadBalancerFeignClient(
						client.getDelegate(), factory(),
						clientFactory(), this.beanFactory);
			} else if (bean instanceof TraceLoadBalancerFeignClient) {
				return bean;
			}
			return new TraceFeignClient(this.beanFactory, (Client) bean);
		}
		return bean;
	}

How can i have any way to use custom LoadBalancerFeignClient? @marcingrzejszczak

xinluke avatar Mar 20 '18 02:03 xinluke