0

spring-rabbitmq 的 opentracing 工具没有定义用于跟踪org.springframework.amqp.rabbit.core.RabbitTemplate#send. 这是代码的链接: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();
        }
    }
}

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

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!

请帮帮我!

4

1 回答 1

2

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

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 Cloud,因此您无法使用它覆盖 AOP 配置,@EnableAspectJAutoProxy因此它始终使用CglibAopProxy.

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

于 2019-05-31T12:57:33.320 回答