Apache Camel – Calling a Method using the Bean Component

Maven Dependencies


Service Class

package com.dineshkrish;

 * @author Dinesh Krishnan

public class MyService {

	public void doSomething(Object message) {



package com.dineshkrish;

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

 * @author Dinesh Krishnan

public class CallMethodCamel_2 {

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

		// creating a camel context
		CamelContext context = new DefaultCamelContext();

		// adding the route to context
		context.addRoutes(new RouteBuilder() {

			public void configure() throws Exception {

				// creating a object
				MyService service = new MyService();

				.bean(service, "doSomething");

		// start the context

		// create a producer and send message
		ProducerTemplate template = context.createProducerTemplate();
		template.sendBody("direct:start", "Your message goes here....");

		// 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.
Your message goes here....

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.