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!
请帮帮我!
答案 0 :(得分:1)
这不是错误。产生该消息的代码如下:
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,因此无法使用该@EnableAspectJAutoProxy
覆盖AOP配置,因此它始终使用CglibAopProxy
。
我只会忽略那个info
。最好不要为框架类别设置这样的日志记录级别。