How to stop a mule flow from running after startup

北战南征 提交于 2019-11-28 06:46:09

问题


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();
        }
    }

}

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.

I am using Mule 3.2.2 without annotations.

Thanks,


回答1:


Instead of trying to stop the flow during the initialization phase, configure it to be stopped when Mule starts:

<flow name="..." initialState="stopped">

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>



回答2:


Alternately there is a properties file called mule-deploy.properties
You can find there, all the flow xml files name are written there manually:-

config.resources=yourFlowName.xml

You can remove the flow name which you don't want to start at the time of Mule application getting started.
But yes, David's solution is recommended, and you should use this solution only as alternative.



来源:https://stackoverflow.com/questions/15387745/how-to-stop-a-mule-flow-from-running-after-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!