DEV Community

Cover image for Apache Camel #4 - Processors
Djordje Bajic
Djordje Bajic

Posted on • Updated on

Apache Camel #4 - Processors

Hello Devs!

Long time no new article!

Guess i have to fix that.

Today we are talking about processors in Apache Camel routes.

Processors are a part of camel which enables us to write our custom components and business logic and implement it in the routes.

There are two ways of using processors.

  1. Creating a class and implementing Processor with process method. This way we can easily write a test and separate processor logic from route itself. It looks something like this in the route.

.process(new CustomProcessor())

Processor itself will look something like this:

public class CustomProcessor implements Processor {

    @Override
    public void process(Exchange exchange) {
         exchange.getIn().setBody("test");
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Functional way.

.process(exchange -> exchange.getIn().setBody("test"))

Even though this way is easier that first, it couples processor logic to route and you could only test it if you test whole route.

My YT: https://www.youtube.com/channel/UC0Ws7Fn3fTjZ9eKH87R_rKA

That would be all for today!
Stay safe,stay cool!

George / Djordje

Latest comments (0)