在提供的服务器上从Mule Studio运行Mule App时,我可以默认情况下从实现接口EndpointMessageNotificationListener的类中“侦听”服务器通知。
当我在运行在集群中的独立环境(版本3.6.1)中部署相同的代码时,我无法检索相同的通知。默认情况下,启用服务器通知需要什么?
我不想在每个应用程序中配置这个--但是也许我们需要?默认情况下,启动骡子服务器以启用服务器通知时是否有配置?(这是在Mule Studio提供的Mule服务器上实现的吗?)
如果我们需要启用每个应用程序中的通知。如何做到这一点?我尝试过(其中com.company.EndpointListener是实现EndpointMessageNotificationListener接口的类):
<spring:bean name="endpointListener" class="com.company.EndpointListener"/>
<notifications>
<notification event="ENDPOINT-MESSAGE"/>
<notification-listener ref="endpointListener"/>
</notifications>(如此处所述:http://www.mulesoft.org/documentation/display/current/Mule+Server+Notifications)
但它什么也做不了。在我们的独立环境中,我的班级仍然没有收到任何通知。有什么建议可以让它发挥作用吗?
发布于 2015-05-06 08:53:23
好的,当我发现问题所在时,这是一个相当模糊的修正。
没有正确启动不同的通知侦听器,从而阻碍了所有其他通知侦听器接收任何通知(这有点危险)。
另一个通知侦听器问题是,它试图在初始化过程中以这种方式读取属性-文件(当部署到Mule Studio使用的服务器时,该方法可以工作):
MyClass.class.getClassLoader().getResourceAsStream("MyFile.file")但我需要把它改为:
Thread.currentThread().getContextClassLoader().getResourceAsStream("MyFile.file")否则,侦听器将导致异常:
org.mule.work.DefaultWorkListener: Work caused exception on 'workCompleted'. Work being executed was: org.mule.context.notification.ServerNotificationManager@5a66c9cf 在此之后,任何通知侦听器都无法接收到任何通知。
一旦我处理了这个案例,所有其他侦听器就开始毫无问题地接收通知。
发布于 2015-10-07 16:13:46
是一个bug:https://www.mulesoft.org/jira/browse/MULE-7183
我也有同样的问题。几天后,我使它无法工作。
根据:
https://docs.mulesoft.com/mule-user-guide/v/3.7/mule-server-notifications#notification-interfaces
有几个通知接口:组件消息通知、端点消息通知、连接通知、自定义通知等。
这里有一些捕获组件和指定消息的方法:
像我这样的解决方案。需要最少的努力和最小的配置。问题是它可以接收点消息:(
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配置中:
<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> {但听众不会被触发。
是不干净的而且是侵扰性的。
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>这也适用于出站端点。
我希望这能帮上忙!
发布于 2016-08-16 02:37:30
对于那些试图达到同样结果的游客来说,这是一个小小的提示。首先,您应该根据希望得到通知的内容实现Java类,如下所示:
package stackoverflow.mule.notifications
. . .
public class MyEndpointNotificationListener implements EndpointMessageNotificationListener<EndpointMessageNotification> {
@Override
public void onNotification(EndpointMessageNotification notification) {
// Whatever you have to do when notified goes here.
}
}然后是你的Mule配置。首先,将通知侦听器注册为Spring:
<spring:beans>
<spring:bean name="MyEndpointNotificationListener"
class="stackoverflow.mule.notifications.MyEndpointNotificationListener"
id="MyEndpointNotificationListener" />
</spring:beans>在它下面,你必须按以下方式注册你的通知:
<notifications>
<notification event="ENDPOINT-MESSAGE"/>
<notification-listener ref="MyEndpointNotificationListener" />
</notifications>然后就到了。现在应该能用了。这已在Mule ESB 3.8 (CE或EE)中使用。
干杯!
https://stackoverflow.com/questions/30035117
复制相似问题