Apache Camel – Processor

Hello everyone, In this post, you will learn How to use Processor Class in Apache Camel. The example has been tested and shared in the post.

Maven Dependencies


Camel Processor

package com.dineshkrish.example51;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

 * @author Dinesh Krishnan

public class MyProcessor implements Processor {

	public void process(Exchange exchange) throws Exception {

		// get message from body
		String message = exchange.getIn().getBody(String.class);

		// apply your changes
		message = "Hello " + message;

		// set new message to body


Main Program

package com.dineshkrish.example51;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

 * @author Dinesh Krishnan

public class ProcessorExample {

	public static void main(String[] args) throws Exception {

		// create the camel context
		CamelContext context = new DefaultCamelContext();

		// adding route to camel context
		context.addRoutes(new RouteBuilder() {
			public void configure() throws Exception {
					.process(new MyProcessor())

		// start the context
		// creating producer template
		ProducerTemplate pTemplate = context.createProducerTemplate();
		pTemplate.sendBody("direct:start", "Dinesh Krishnan");
		// creating consumer template
		ConsumerTemplate cTemplate = context.createConsumerTemplate();
		String message = cTemplate.receiveBody("seda:end", String.class);

		// stop the context




SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hello Dinesh Krishnan