Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When we are processing messages and using Java code for that purpose (ie. via bean class or processor class), it is often quite necessary to create a fresh exchange instance. Thus, if you need to create an Exchange object, the easiest approach is to invoke the methods of the ExchangeBuilder class.

ExchangeBuilder class

The fully qualified name of the ExchangeBuilder class is as follows:

...

Code Block
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
...
Exchange exch = ExchangeBuilder.anExchange(myCamelCtx)
                    .withBody("Hello World!")
                    .withHeader("username", "janedoe")
                    .withHeader("password", "pa$$w0rd")
                    .build();

ExchangeBuilder methods

The ExchangeBuilder class supports the following methods:

...