是一个错误:
https://www.mulesoft.org/jira/browse/MULE-7183
我也有同样的问题。几天了,我无法让它工作:(
根据:
https://docs.mulesoft.com/mule-user-guide/v/3.7/mule-server-notifications#notification-interfaces
有几种通知接口:组件消息通知、端点消息通知、连接通知、自定义通知、ETC
这里有一些捕获组件和指定消息的方法:
像我这样的解决方案。需要最少的工作和最少的配置。问题是它可以接收 enpoint 消息:(
import org.apache.log4j.Logger;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;
import org.mule.api.context.notification.MessageProcessorNotificationListener;
import org.mule.api.processor.MessageProcessor;
import org.mule.context.notification.MessageProcessorNotification;
public class ComponentMessageProcessor implements MessageProcessorNotificationListener<MessageProcessorNotification> {
private Logger log = Logger.getLogger(ComponentMessageProcessor.class);
@Override
public void onNotification(MessageProcessorNotification m) {
MuleEvent ev = m.getSource();
MuleMessage msg = ev.getMessage();
Object payload = msg.getPayload();
String ref = payload != null ? payload.toString() : "null";
MessageProcessor proc = m.getProcessor();
log.info(String.format("\n\n\n[%s][%s][%s][%s]\n\n\n", ev.getFlowConstruct().getName(),m.getProcessorPath(), proc.getClass().getSimpleName(),ref));
}
}
在 mule xml 配置中:
<spring:beans>
<spring:bean name="componentMessageProcessor" class="com.mycompany.ComponentMessageProcessor"></spring:bean>
</spring:beans>
或者在spring配置中:
<bean name="componentMessageProcessor" class="com.mycompany.componentMessageProcessor"></bean>
我尝试使用以下方法捕获端点消息:
implements EndpointMessageNotificationListener<EndpointMessageNotification>{
instead of
implements MessageProcessorNotificationListener<MessageProcessorNotification> {
但是没有触发监听器。
来源:Mule - Intercept all flows
不干净且具有侵入性。
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
import org.mule.api.processor.MessageProcessor;
public class EndpointMessageProcesor implements MessageProcessor{
@Override
public MuleEvent process(MuleEvent event) throws MuleException {
System.out.println("\n\n\n\n\n"+event.getMessage().getPayload()+"\n\n\n\n");
return event;
}
}
在骡子配置中:
<jms:inbound-endpoint queue="queue.req" ...>
<custom-processor class="com.mycompany.EndpointMessageProcesor"></custom-processor>
</jms:inbound-endpoint>
这也适用于出站端点。
我希望这对某人有帮助!