gpt4 book ai didi

Mule MessageReceiver 周围的 AspectJ

转载 作者:行者123 更新时间:2023-12-02 15:23:18 26 4
gpt4 key购买 nike

我正在寻找围绕 Mule Flow 的一个方面,IE 我想定义一个 @Around当某些东西进入 Mule 流时就会触发它,这样我就可以执行自己的统计数据收集。我还没有找到一个简单的“Flow”类来包装,但我已经看到了 MessageReceiver是一个好类,或者至少是这个类的实现。

但是我不是 AspectJ 方面的专家,我无法让它发挥作用。我有我的@Aspect具有如下所示方法的类。

@Around("execution(public * org.mule.api.transport.MessageReceiver+.*(..))")
public Object addMonitor(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("Before");
Object object = pjp.proceed();
System.out.println("After");
return object;
}

但是当 HttpMessageReceiver 中的方法时,我无法打印出之前/之后的字符串叫做。我在流程中设置了一个调试点,可以看到 org.mule.transport.AbstractMessageReceiver.routeMessage(MuleMessage message)正在被调用,这是 MessageReceiver 的实现但我从来没有看到对我的守护者的调用。

是否可以在 Mule 中执行此类 Aspect?

//编辑:如前所述,我是 AspectJ 和 AOP 的新手,所以我会说我在 Mule 中使用 spring 来处理我的 @Aspect类(class)。我有关于 Spring 处理的 bean 的示例,但不适用于不由 spring 管理的常规 POJO。我的 Spring 配置如下:

<spring:beans>
<context:component-scan base-package="com.example" />
<context:annotation-config />
<aop:aspectj-autoproxy />
</spring:beans>

最佳答案

我需要加载时编织,所以我必须为aspectjweaver和spring-instrument添加-javaagent,并添加一个META-INF/aop.xml链接到我的 @Aspect 类,但是一旦我这样做了,我就可以做 @Around("call(* org.mule.api.transport.MessageReceiver.routeMessage(org .mule.api.MuleMessage))") 获取 Mule 的调用。

关于Mule MessageReceiver 周围的 AspectJ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15910422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com