Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

jms - How to stop a mule flow from running after startup

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...