You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ganga_camel <ga...@gmail.com> on 2015/12/17 15:35:54 UTC

Camel Routes: Identify end of Processing in a Route

Hi,

I am new to camel. I understand that Camel routes once started continue to
be active and in running status unless its manually stopped.

I have a requirement where the route should automatically stop after the
processing of all the records are complete. 

Is there a way we can programitically force stop the route once all the
records processing is complete?

Thanks,
Ganga





--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Routes-Identify-end-of-Processing-in-a-Route-tp5775224.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Camel Routes: Identify end of Processing in a Route

Posted by "Mills, Gary (GE Energy Management, consultant)" <ga...@ge.com>.
You can do something like this:
Set the route in the header...

public class RouteStopProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        String routeIdToRestart = (String)exchange.getIn().getHeader("routeIdToRestart");
        CamelContext context = exchange.getContext();
        context.stopRoute(routeIdToRestart);
    }
}
public class RouteStartProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        String routeIdToRestart = (String)exchange.getIn().getHeader("routeIdToRestart");
        CamelContext context = exchange.getContext();
        context.startRoute(routeIdToRestart);
    }
}
public class RestartContextProcessor implements Processor {
	
	private Logger log = LoggerFactory.getLogger(RestartContextProcessor.class.getName());
	
    @Override
    public void process(Exchange exchange) throws Exception {
        CamelContext context = exchange.getContext();
        context.getInflightRepository().remove(exchange);
        log.info("No Queue Activity for set period, will restart the context, ... Stopping Context: " + context.getName());
        context.stop();
        Thread.sleep(10000);
        context.start();
        log.info("Restarting Application Context due to no Queue Activity, ... Started Context: " + context.getName());
    }
}

<route id="fadecAssetAndStatusMessageProcessing"  autoStartup="false" >
            <from uri="sftp://{{ftpUsername}}@{{ftpHost}}:{{ftpPort}}/{{ftpPath}}?password={{ftpPassword}}&amp;delete=false&amp;move={{ftpMoveToPath}}&amp;localWorkDirectory={{ftpLocalWorkDir}}&amp;binary=true&amp;readLock={{ftpReadLock}}&amp;filter=#fadecXlsxFilter&amp;consumer.delay=600s&amp;disconnect=true" />
            <choice>
                <when>
                    <simple>${in.header[CamelFileName]} == 'FADEC_Fault_Codes.xlsx'</simple>
                    <setHeader headerName="routeIdToRestart">
                        <constant>deltaFadecMQ</constant>
                    </setHeader>
                    <process ref="routeStopProcessor"/>
                    <to uri="sql:truncate table geip_fadec.fadec_status_message"/>
                    <process ref="faultMessageXlsxProcessor" />
                    <split>
                        <simple>${body}</simple>
                        <log message="Inserting into table geip_fadec.fadec_status_message: ${in.body}" loggingLevel="DEBUG"/>
                        <to uri="sql:{{faultMessageInsertSQL}}"/>
                    </split>
                    <process ref="routeStartProcessor"/>
                </when>
                <when>
                    <simple>${in.header[CamelFileName]} == "delta_asset_ids.xlsx"</simple>
                    <setHeader headerName="routeIdToRestart">
                        <constant>deltaFadecMQ</constant>
                    </setHeader>
                    <process ref="routeStopProcessor"/>
                    <to uri="sql:truncate table geip_fadec.asset_tag"/>
                    <to uri="sql:delete from geip_fadec.asset where asset_id != &#39;&#39;"/>
                    <to uri="sql:delete from geip_fadec.aircraft where ship_number != &#39;&#39;"/>
                    <process ref="aircraftAssetXlsxProcessor" />
                    <process ref="routeStartProcessor"/>
                </when>

-----Original Message-----
From: ganga_camel [mailto:ganga.db@gmail.com] 
Sent: Thursday, December 17, 2015 8:36 AM
To: users@camel.apache.org
Subject: Camel Routes: Identify end of Processing in a Route

Hi,

I am new to camel. I understand that Camel routes once started continue to be active and in running status unless its manually stopped.

I have a requirement where the route should automatically stop after the processing of all the records are complete. 

Is there a way we can programitically force stop the route once all the records processing is complete?

Thanks,
Ganga





--
View this message in context: https://urldefense.proofpoint.com/v2/url?u=http-3A__camel.465427.n5.nabble.com_Camel-2DRoutes-2DIdentify-2Dend-2Dof-2DProcessing-2Din-2Da-2DRoute-2Dtp5775224.html&d=CwICAg&c=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI&r=Hb1nXb7biSqY9NYScX39HfYaeuqILlgaLYiYNWt8oJo&m=9xST_mmOc0yWL6UJjx3ixAWRJzGfOUYVmXeJmEmRGvQ&s=XFPGPFZb9yi0_dOwjNj1TJARhjpeWrDyFeL0fV_a3gg&e=
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Routes: Identify end of Processing in a Route

Posted by Christian Schneider <ch...@die-schneider.net>.
Camel routes are event based. So each event is separate. There is no 
real notion of "all records".

It is a recurring request though. So maybe we are missing a camel batch 
processing/ETL API.

Christian

On 17.12.2015 15:35, ganga_camel wrote:
> Hi,
>
> I am new to camel. I understand that Camel routes once started continue to
> be active and in running status unless its manually stopped.
>
> I have a requirement where the route should automatically stop after the
> processing of all the records are complete.
>
> Is there a way we can programitically force stop the route once all the
> records processing is complete?
>
> Thanks,
> Ganga
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Routes-Identify-end-of-Processing-in-a-Route-tp5775224.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com