0
votes

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,

2

2 Answers

3
votes

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>
1
votes

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.