是一個錯誤: 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));
}
}
而且在騾子的XML配置:
在spring配置
<spring:beans>
<spring:bean name="componentMessageProcessor" class="com.mycompany.ComponentMessageProcessor"></spring:bean>
</spring:beans>
或者:
<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>
這工作在出站端點也。
我希望這可以幫助別人!