[[process-eip]]
= Process EIP
:docTitle: Process
:description: Calls a Camel processor
:since: 
:supportLevel: Stable

The http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Processor.html[Processor] interface is used to implement consumers of message exchanges or to implement a xref:message-translator.adoc[Message Translator]

== Options

// eip options: START
The Process EIP supports 1 options which are listed below:

[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *ref* | *Required* Reference to the Processor to lookup in the registry to use. |  | String
|===
// eip options: END

== Samples

=== Using a processor in a route

Once you have written a class which implements processor like this...

[source,java]
----
public class MyProcessor implements Processor {
  public void process(Exchange exchange) throws Exception {
    // do something...
  }
}
----

You can then easily use this inside a route by declaring the bean in
Spring, say via the XML (or registering it in JNDI if that is your
xref:latest@manual:ROOT:registry.adoc[Registry])

[source,xml]
--------------------------------------------------------
<bean id="myProcessor" class="com.acme.MyProcessor"/>
--------------------------------------------------------

Then in Camel you can do

[source,java]
----
from("activemq:myQueue").to("myProcessor");
----

=== Using the process DSL

In your route you can also use the `process` DSL syntax for invoking a
processor.

[source,java]
----
Processor myProcessor = new MyProcessor();
...
from("activemq:myQueue").process(myProcessor);
----

If you need to lookup the processor in the xref:latest@manual:ROOT:registry.adoc[Registry]
then you should use the *processRef* DSL:

[source,java]
----
from("activemq:myQueue").processRef("myProcessor");
----

== Why use process when you can use to instead?

The process can be used in routes as an anonymous inner class such:

[source,java]
----
    from("activemq:myQueue").process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            String payload = exchange.getIn().getBody(String.class);
            // do something with the payload and/or exchange here
           exchange.getIn().setBody("Changed body");
       }
    }).to("activemq:myOtherQueue");
----

This is usable for quickly whirling up some code. If the code in the
inner class gets a bit more complicated it is of course advised to
refactor it into a separate class.

== Turning your processor into a full Component

There is a base class called
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ProcessorEndpoint.html[ProcessorEndpoint]
which supports the full xref:latest@manual:ROOT:endpoint.adoc[Endpoint] semantics given a
Processor instance.

So you just need to create a https://github.com/apache/camel/tree/master/components[Component] class by
deriving from
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/DefaultComponent.html[DefaultComponent]
which returns instances of ProcessorEndpoint. For more details see
xref:latest@manual:ROOT:writing-components.adoc[Writing Components]
