이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 43. Exchange Interface


Abstract

This chapter describes the Exchange interface. Since the refactoring of the camel-core module performed in Apache Camel 2.0, there is no longer any necessity to define custom exchange types. The DefaultExchange implementation can now be used in all cases.

43.1. The Exchange Interface

Overview

An instance of org.apache.camel.Exchange type encapsulates the current message passing through a route, with additional metadata encoded as exchange properties.

Figure 43.1, “Exchange Inheritance Hierarchy” shows the inheritance hierarchy for the exchange type. The default implementation, DefaultExchange, is always used.

Figure 43.1. Exchange Inheritance Hierarchy

Exchange inheritance hierarchy

The Exchange interface

Example 43.1, “Exchange Interface” shows the definition of the org.apache.camel.Exchange interface.

Example 43.1. Exchange Interface

package org.apache.camel;

import java.util.Map;

import org.apache.camel.spi.Synchronization;
import org.apache.camel.spi.UnitOfWork;

public interface Exchange {
    // Exchange property names (string constants)
    // (Not shown here)
    ...

    ExchangePattern getPattern();
    void setPattern(ExchangePattern pattern);

    Object getProperty(String name);
    Object getProperty(String name, Object defaultValue);
    <T> T  getProperty(String name, Class<T> type);
    <T> T  getProperty(String name, Object defaultValue, Class<T> type);
    void   setProperty(String name, Object value);
    Object removeProperty(String name);
    Map<String, Object> getProperties();
    boolean hasProperties();

    Message getIn();
    <T> T   getIn(Class<T> type);
    void    setIn(Message in);

    Message getOut();
    <T> T   getOut(Class<T> type);
    void    setOut(Message out);
    boolean hasOut();

    Throwable getException();
    <T> T     getException(Class<T> type);
    void      setException(Throwable e);

    boolean isFailed();

    boolean isTransacted();

    boolean isRollbackOnly();

    CamelContext getContext();

    Exchange copy();

    Endpoint getFromEndpoint();
    void     setFromEndpoint(Endpoint fromEndpoint);

    String getFromRouteId();
    void   setFromRouteId(String fromRouteId);

    UnitOfWork getUnitOfWork();
    void setUnitOfWork(UnitOfWork unitOfWork);

    String getExchangeId();
    void setExchangeId(String id);

    void addOnCompletion(Synchronization onCompletion);
    void handoverCompletions(Exchange target);
}

Exchange methods

The Exchange interface defines the following methods:

  • getPattern(), setPattern() — The exchange pattern can be one of the values enumerated in org.apache.camel.ExchangePattern. The following exchange pattern values are supported:

    • InOnly
    • RobustInOnly
    • InOut
    • InOptionalOut
    • OutOnly
    • RobustOutOnly
    • OutIn
    • OutOptionalIn
  • setProperty(), getProperty(), getProperties(), removeProperty(), hasProperties() — Use the property setter and getter methods to associate named properties with the exchange instance. The properties consist of miscellaneous metadata that you might need for your component implementation.
  • setIn(), getIn() — Setter and getter methods for the In message.

    The getIn() implementation provided by the DefaultExchange class implements lazy creation semantics: if the In message is null when getIn() is called, the DefaultExchange class creates a default In message.

  • setOut(), getOut(), hasOut() — Setter and getter methods for the Out message.

    The getOut() method implicitly supports lazy creation of an Out message. That is, if the current Out message is null, a new message instance is automatically created.

  • setException(), getException() — Getter and setter methods for an exception object (of Throwable type).
  • isFailed() — Returns true, if the exchange failed either due to an exception or due to a fault.
  • isTransacted() — Returns true, if the exchange is transacted.
  • isRollback() — Returns true, if the exchange is marked for rollback.
  • getContext() — Returns a reference to the associated CamelContext instance.
  • copy() — Creates a new, identical (apart from the exchange ID) copy of the current custom exchange object. The body and headers of the In message, the Out message (if any), and the Fault message (if any) are also copied by this operation.
  • setFromEndpoint(), getFromEndpoint() — Getter and setter methods for the consumer endpoint that orginated this message (which is typically the endpoint appearing in the from() DSL command at the start of a route).
  • setFromRouteId(), getFromRouteId() — Getters and setters for the route ID that originated this exchange. The getFromRouteId() method should only be called internally.
  • setUnitOfWork(), getUnitOfWork() — Getter and setter methods for the org.apache.camel.spi.UnitOfWork bean property. This property is only required for exchanges that can participate in a transaction.
  • setExchangeId(), getExchangeId() — Getter and setter methods for the exchange ID. Whether or not a custom component uses and exchange ID is an implementation detail.
  • addOnCompletion() — Adds an org.apache.camel.spi.Synchronization callback object, which gets called when processing of the exchange has completed.
  • handoverCompletions() — Hands over all of the OnCompletion callback objects to the specified exchange object.
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.