Reputation: 1655
I'm trying to setup a route that process files, here is my route configuration:
@Component
public class MyRoute extends RouteBuilder {
public static final String FIRST_ROUTE = "firstRoute";
public static final String SECOND_ROUTE = "secondRoute";
private final Processor myProcessor;
@Autowired
public MyRoute (@Qualifier("my.processor") Processor myProcessor) {
this.myProcessor= myProcessor;
}
@Override
public void configure() throws Exception {
from("file://{{data.input.dir}}?moveFailed=errors&delete=true&doneFileName=ACK-${file:name}&include=MY-FILE-FIRST.*")
.routeId(FIRST_ROUTE)
.process(myProcessor);
from("file://{{data.input.dir}}?moveFailed=errors&delete=true&doneFileName=ACK-${file:name}&include=MY-FILE-SECOND.*")
.routeId(SECOND_ROUTE)
.process(myProcessor);
}
}
As you can see I have two route for two files that have different name (one with FIRST, one with SECOND). I want to trigger the process with variable to avoid to check the filename inside the process.
Currently my process function look like that:
public void process(Exchange exchange) throws Exception
What I want is something like that:
public void process(Exchange exchange, String identifier) throws Exception
And have the identifier set in the route definition (it's static, not depending on the filename, I need to have "FIRST"
for the first route, and "SECOND"
for the second one).
Is this possible ?
Upvotes: 0
Views: 1841
Reputation: 368
Because a process interface signature only takes an Exchange parameter, we cannot do process(Exchange exchange, String identifier)
.
Instead we can create a bean and call the method from the route like below.
from("file://{{data.input.dir}}?moveFailed=errors&delete=true&doneFileName=ACK-${file:name}&include=MY-FILE-SECOND.*")
.routeId(SECOND_ROUTE)
.bean(myBean,"process(*, " + SECOND + ")");
Upvotes: 3