I'm using JBoss Fuse 6.1.0 with Camel 2.10.0.redhat-60024.
The list of routes are already known. For example: #start, #step1, #step2, #step3, #finish
.
But I don't know sequence. Or sometimes some route may not be needed. I will know that only at #router
route (please, see below code).
For example: #start, #step2, #step1, #step3, #finish.
or #start, #step1, #step3, #finish.
or etc.
But Camel 2.10.0 doesn't have such thing as dynamicRouter
. I decided to do something like that:
<?xml version="1.0" encoding="UTF-8"?>
...
<camelContext id="blueprintContext" trace="true"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="start">
<from uri="..." />
<to uri="vm:router" />
</route>
<route id="router">
<from uri="vm:router" />
<bean ref="stepGenerator" method="nextStep" />
<choice>
<when>
<simple>${header.step} contains 'step1'</simple>
<to uri="vm:step1" />
</when>
<when>
<simple>${header.step} contains 'step2'</simple>
<to uri="vm:step2" />
</when>
<when>
<simple>${header.step} contains 'step3'</simple>
<to uri="vm:step3" />
</when>
<when>
<simple>${header.step} contains 'finish'</simple>
<to uri="vm:finish" />
</when>
</choice>
</route>
<route id="step1">
<from uri="vm:step1" />
<log message="Step 1 started." />
<!-- Some logic -->
<to uri="vm:router" />
</route>
<route id="step2">
<from uri="vm:step2" />
<log message="Step 2 started." />
<!-- Some logic -->
<to uri="vm:router" />
</route>
<route id="step3">
<from uri="vm:step3" />
<log message="Step 3 started." />
<!-- Some logic -->
<to uri="vm:router" />
</route>
<route id="finish">
<from uri="vm:finish" />
<log message="Finished!" />
</route>
</camelContext>
Imagine that we have next sequence: #start, #step1, #step2, #step3, #finish
. If you to try to run this will be stopped at #start -> #router-> #step1
.
In #step1
<to uri="vm:router" />
not working. If you call route twice it will not work. Why?
How can I solve this situation in Camel 2.10.0?
According to the camel website the dynamic Router pattern was introduced in Version 2.5. I am sure that will work for you...