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.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
2.5. Creating Exchange Instances
Overview 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
When processing messages with Java code (for example, in a bean class or in a processor class), it is often necessary to create a fresh exchange instance. If you need to create an
Exchange
object, the easiest approach is to invoke the methods of the ExchangeBuilder
class, as described here.
ExchangeBuilder class 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The fully qualified name of the
ExchangeBuilder
class is as follows:
org.apache.camel.builder.ExchangeBuilder
org.apache.camel.builder.ExchangeBuilder
The
ExchangeBuilder
exposes the static method, anExchange
, which you can use to start building an exchange object.
Example 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
For example, the following code creates a new exchange object containing the message body string,
Hello World!
, and with headers containing username and password credentials:
ExchangeBuilder methods 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
The
ExchangeBuilder
class supports the following methods:
ExchangeBuilder anExchange(CamelContext context)
- (static method) Initiate building an exchange object.
Exchange build()
- Build the exchange.
ExchangeBuilder withBody(Object body)
- Set the message body on the exchange (that is, sets the exchange's In message body).
ExchangeBuilder withHeader(String key, Object value)
- Set a header on the exchange (that is, sets a header on the exchange's In message).
ExchangeBuilder withPattern(ExchangePattern pattern)
- Sets the exchange pattern on the exchange.
ExchangeBuilder withProperty(String key, Object value)
- Sets a property on the exchange.