camel processor

Processor in camel.


Processor in camel is an entity which is responsible to modify and process incoming message.Mostly EIP in camel are processor.It is an interface in camel and to create a processor, we need to implement it and override one method

public void process(Exchange exchange) throws Exception;

  • Right click on package and create a java class for example MyProcessor.



  • Copy below code in MyProcessor.

  •  
    	import org.apache.camel.Exchange;
    	public class MyProcessor implements org.apache.camel.Processor{
    
    	public void process(Exchange exchange) throws Exception {
    		System.out.println("processing" + exchange.getIn().getBody(String.class));
    	}
    }
    

    Here process method has Exchange as input and it can get incoming message and modify it and again can put in exchange.We just read that incoming message

    We can add our processor in this case MyProcessor in route using process method, as shown below

     	
    	from("file:input?noop=true")
    	.process(new MyProcessor())
    	.to("jms:queue:preparationforinterview");
    

    Similarly We can add our processor in this case MyProcessor in spring route using bean, as shown below

     	
    	<bean id="myprocessor" class="com.preparationforinterview.jms.MyProcessor"/>
    	
    	<route>
    	<from uri="file:input?noop=true"/>
    	<process ref="myprocessor"/>
    	<to uri="jms:queue:preparationforinterview"/>
    	</route>
    



Visit Others Links

Camel Introduction
Camel Setup
File Copy Example Using Camel
File Copy Example In Camel Using Spring
JMS Message Transfer Example Using Camel
JMS Message Transfer Example In Camel Using Spring
Processor In Camel
Object to JSON Transfer Example Using Spring In Camel
Camel With Bean Injection Example Using Spring DSL
Camel With Bean Injection Registry Example Using Java DSL
Camel Bean Parameter Binding Example Using Java DSL
Camel Error Handling With Redelivery Example Using Java DSL
Camel Exception Handling With Example Using Java DSL
Camel JUnit Test With Example Using Java DSL
Camel JUnit Test With Example Using Spring DSL
Camel Unit Test With Mock Component Example
Camel With Stream Component Example
Camel In-Memory Messaging Example Using Direct
Camel With Timer And Quartz Example
Camel Aggregator EIP Example
Camel Splitter EIP Example
Camel Routing Slip EIP Example
Camel Dynamic Router EIP Example
Camel Load Balancer EIP Example
Top Camel Interview Question
© 2019 PreparationForInterview.com