0

I'm processing files with a Camel route like this:

    <route>
        <from uri="file:inbox?delete=true"/>
        <recipientList>
            <simple>exec://process.sh?args=inbox/${file:name}</simple>
        </recipientList>
        <log message="processed ${file:name}: ${body.stdout} ${body.stderr}"/>
    </route>

Now I'd like the route to fail when process.sh finishes with nonzero exit-code. I found ${headers.CamelExecExitValue} but don't really know what to do with it.

In the example above, the file should not get deleted when process.sh fails. In my actual use-case, the route consumes files from a JMS queue and I want the file to stay in the queue. I think this can be done with <transacted/> but need to know how to fail the route.

sba
  • 1,829
  • 19
  • 27

1 Answers1

0

I found How to define exception to be thrown through ref in Apache Camel which in combination with CamelExecExitValue lets me abort this way:

    <route>
        <from uri="file:inbox?delete=true"/>
        <to uri="exec://process.sh"/>
        <choice>
            <when>
                <simple>
                    ${headers.CamelExecExitValue} != 0
                </simple>
                <throwException exceptionType="java.lang.RuntimeException" message="failed importing ${file:name}: ${body.stdout} ${body.stderr}"/>
            </when>
        </choice>
        <log message="processed ${file:name}"/>
    </route>

A bit verbose for my taste but works fine.

sba
  • 1,829
  • 19
  • 27