Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
44.2. Implementing a Simple Processor
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This section describes how to implement a simple processor that executes message processing logic before delegating the exchange to the next processor in the route.
Processor interface 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Simple processors are created by implementing the
org.apache.camel.Processor
interface. As shown in Example 44.2, “Processor Interface”, the interface defines a single method, process()
, which processes an exchange object.
Example 44.2. Processor Interface
package org.apache.camel; public interface Processor { void process(Exchange exchange) throws Exception; }
package org.apache.camel;
public interface Processor {
void process(Exchange exchange) throws Exception;
}
Implementing the Processor interface 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To create a simple processor you must implement the
Processor
interface and provide the logic for the process()
method. Example 44.3, “Simple Processor Implementation” shows the outline of a simple processor implementation.
Example 44.3. Simple Processor Implementation
All of the code in the
process()
method gets executed before the exchange object is delegated to the next processor in the chain.
For examples of how to access the message body and header values inside a simple processor, see Section 44.3, “Accessing Message Content”.
Inserting the simple processor into a route 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Use the
process()
DSL command to insert a simple processor into a route. Create an instance of your custom processor and then pass this instance as an argument to the process()
method, as follows:
org.apache.camel.Processor myProc = new MyProcessor(); from("SourceURL").process(myProc).to("TargetURL");
org.apache.camel.Processor myProc = new MyProcessor();
from("SourceURL").process(myProc).to("TargetURL");