user3735766
user3735766

Reputation: 31

How to chain multiple processors in Camel

How can I add a chain of processors to my Camel route, e.g.:

from("file:source?noop=true")
.process(new MyProcessor1()).to(
            "file:destination?fileName=output.csv");

Can add multiple processors sequentially to my route like this:

from("file:source?noop=true")
    .process(new MyProcessor1()).process(new Processor2()) .to(
            "file:destination?fileName=output.csv");

Alternatively, can I use a chained processor like this:

 DefaultMessageProcessorChainBuilder builder=new DefaultMessageProcessorChainBuilder();
builder.chain(new TestMessageProcessor("1"),
  new TestMessageProcessor("2"),
  new TestMessageProcessor("3"));
MessageProcessor mpChain=builder.build();

Any thoughts on how we can achieve the same with Camel?

Upvotes: 0

Views: 4328

Answers (1)

Ben ODay
Ben ODay

Reputation: 21015

a Camel route defines the chain of processors using from() and to()...

enter image description here

an Exchange is created when the route is invoked and each processor in a route can decorate it along the way...

from(endpoint).to(step1).to(step2)...

Upvotes: 3

Related Questions