启动后如何阻止m子流运行 [英] How to stop a mule flow from running after startup
问题描述
我有一个以jms入站端点开头的m子流. 我的要求是防止队列读取任何消息,直到我显式启用端点的连接器为止. 因此,我有一个实现MuleContextNotificationListener的Initializer,重写如下的onNotification:
I have a mule flow that starts with a jms inbound endpoint. My requirement is to prevent the queue from reading any messages until I explicitly enable the connector for the endpoint. So I have an Initializer implementing MuleContextNotificationListener, override onNotification like below:
@Override
public void onNotification(MuleContextNotification ctxNotification) {
System.out.println("Notification order event: " + ctxNotification.getActionName() );
if(ctxNotification.getAction() == MuleContextNotification.CONTEXT_STARTING
|| ctxNotification.getAction() == MuleContextNotification.CONTEXT_STARTED){
try{
//Startup with the Staging and Error Q readers disabled.
System.out.println("STOPPING QUEUES : Staging and Error Queues");
//ctxNotification.getMuleContext().getRegistry().lookupConnector("lynxJMSConnectorStagingQReaderNormal").stop();
ctxNotification.getMuleContext().getRegistry().lookupConnector("lynxJMSConnectorStagingQReaderDR").stop();
ctxNotification.getMuleContext().getRegistry().lookupConnector("lynxJMSConnectorErrorQReader").stop();
ctxNotification.getMuleContext().getRegistry().lookupEndpointFactory().getInboundEndpoint("errorQueueReader").stop();
System.out.println("STOPPED QUEUES");
}catch(MuleException me){
me.printStackTrace();
}
}
}
但是,即使在应用程序初始化时,流程仍然开始(从jms队列中读取消息).连接器初始化后该怎么做才能拦截?如果没有,我应该使用什么机制来阻止连接器读取它.我已经有了从http调用启动/停止连接器的代码.
But the flow still kicks off (reads messages from the jms queue) even while the application is initializing. What should I do to intercept when a connector is initialized so I can stop it? If not, what mechanism should I use to stop the connector from reading it. I already have the code to start/stop the connector from an http call.
我正在使用不带注释的Mule 3.2.2.
I am using Mule 3.2.2 without annotations.
谢谢
推荐答案
不要在初始化阶段尝试停止流,而是配置为在Mule启动时将其停止:
Instead of trying to stop the flow during the initialization phase, configure it to be stopped when Mule starts:
<flow name="..." initialState="stopped">
然后在适当的时候让您的自定义逻辑启动它,例如通过使用MEL:
then have your custom logic start it when the time is good, for example by using MEL:
<expression-component>app.registry.targetFlow.start();</expression-component>
这篇关于启动后如何阻止m子流运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!