在定义用于跟踪 RabbitMQ 发送的方面时修复切入点定义错误

Fixing the pointcut definition error while defining an aspect for tracing the RabbitMQ send

spring-rabbitmq 的 opentracing 工具没有为跟踪 org.springframework.amqp.rabbit.core.RabbitTemplate#send 定义的方面。这是代码的 link:RabbitMqSendTracingAspect.java

我尝试实现它并在定义切入点时遇到一些严重错误。

这是我的代码:


@Aspect
@Configuration
public class AmqpSendTracingAspect {
    private final Tracer tracer;

    public AmqpSendTracingAspect(Tracer tracer) {
        this.tracer = tracer;
    }

    @Around(value = "execution(* org.springframework.amqp.core.AmqpTemplate.send(..)) " +
            "&& args(exchange,routingKey, message)", 
            argNames = "pjp,exchange,routingKey,message")
    public Object traceAmqpSend(ProceedingJoinPoint pjp, 
        String exchange, String routingKey, Message message) throws Throwable {

        final Object[] args = pjp.getArgs();

        System.out.println("Aspect RUnning");

        final MessageProperties messageProperties = message.getMessageProperties();

        Scope scope = AmqpTracingUtils.buildSendSpan(tracer, messageProperties);
        tracer.inject(
                scope.span().context(),
                Format.Builtin.TEXT_MAP,
                new AmqpInjectAdapter(messageProperties));

        AmqpSpanDecorator spanDecorator = new AmqpSpanDecorator();
        spanDecorator.onSend(messageProperties, exchange, routingKey, scope.span());

        args[2] = message;

        try {
            return pjp.proceed(args);
        } catch (Exception ex) {
            spanDecorator.onError(ex, scope.span());
            throw ex;
        } finally {
            scope.close();
        }
    }
}

即使我使用 @EnableAspectJAutoProxy(proxyTargetClass = false)

进行注释,我也会从 CglibAopProxy 框架中收到以下错误
Unable to proxy interface-implementing method [public final void org.springframework.amqp.rabbit.core.RabbitTemplate.start()] because it is marked as final: Consider using interface-based JDK proxies instead!

Unable to proxy interface-implementing method [public final void org.springframework.amqp.rabbit.core.RabbitTemplate.stop()] because it is marked as final: Consider using interface-based JDK proxies instead!

请帮帮我!

这不是错误。产生该消息的代码是这样的:

if (implementsInterface(method, ifcs)) {
                        logger.info("Unable to proxy interface-implementing method [" + method + "] because " +
                                "it is marked as final: Consider using interface-based JDK proxies instead!");
                    }

因此,它是一个 info,它完全不会阻止您的应用程序在之后继续工作。只是 RabbitTemplate.start() 方法不会被代理的指针,这绝对不应该被代理。所以,到目前为止,你还不错。

我认为既然你使用了 Spring 云,你就不能用那个 @EnableAspectJAutoProxy 覆盖 AOP 配置,因此它总是使用 CglibAopProxy.

我会忽略 info。最好不要为框架类别设置这样的日志记录级别。