第 43 章 Exchange Interface


摘要

本章论述了 Exchange 界面。由于重构了在 Apache Camel 2.0 中执行的 camelcore 模块,因此不再需要定义自定义交换类型。现在,在所有情况下都可以使用 DefaultExchange 实现。

43.1. Exchange Interface

概述

org.apache.camel.Exchange 类型的实例封装当前通过路由传递的消息,提供额外的元数据编码为交换属性。

图 43.1 “交换继承层次结构” 显示交换类型的继承层次结构。默认实现( DefaultExchange )是始终使用。

图 43.1. 交换继承层次结构

Exchange 接口

例 43.1 “Exchange Interface” 显示 org.apache.camel.Exchange 接口的定义。

例 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);
}
Copy to Clipboard Toggle word wrap

Exchange 方法

Exchange 接口定义了以下方法:

  • getPattern(), setPattern() the exchange pattern 可以是 org.apache.camel.ExchangePatmel.ExchangePattern.ExchangePattern.ExchangePattern.ExchangePattern.ExchangePattern. .支持以下交换模式值:

    • InOnly
    • RobustInOnly
    • InOut
    • InoptionalOut
    • OutOnly
    • RobustOutOnly
    • OutIn
    • OutOptionalIn
  • setProperty(), getProperty(), getProperties (), removeProperty (), have Properties()有Properties() 使用属性 setter 和 getter 方法将命名的属性与交换实例相关联。属性包含您的组件实施可能需要的其它元数据。
  • setIn(), getIn() Infoblox->_<Setter 和 getter 方法用于 In 消息。

    DefaultExchange 类提供的 getIn() 实施实施 lazy creation语义:如果 In message 为 null,则 DefaultExchange 类会创建一个默认的 In 消息。

  • setOut(), getOut() , , 具有Out() abrt- theSetter 和 getter 方法(用于 Out 消息)。

    getOut() 方法隐式支持创建 Out 消息。也就是说,如果当前 Out 消息 为空,则会自动创建新的消息实例。

  • setException(), getException() 10.10.10.2- theGetter 和 setter 方法用于异常对象( 类型)。
  • 对于因为异常或故障而失败的交换失败,则 isFailed() 3.10.0--abrtRe returns true
  • 如果交换被转换,则 isTransacted() to the 时间为 to- the the Transli's true
  • 如果交换被标记为回滚,则 isRollback() toRollback()to and-abrtRe returns true
  • Getcontext() InventoryService-evictionRe returns 对关联的 CamelContext 实例的引用。
  • copy() Equal-jaxbCreates a new identical(来自交换 ID 的部分)副本当前自定义交换对象。In 消息的正文 和标头Out 消息(若有)和故障消息(若有)也被这个操作复制。
  • setFromEndpoint(), getFromEndpoint() 时间为发布此消息的消费者端点的 setter 和 setter 方法(这通常是端点在路由启动时出现在 from() DSL 命令中)。
  • setFromRouteId(), getFromRouteId() 时间()和 setters,查找源自此交换的路由 ID。getFromRouteId() 方法应该只在内部调用。
  • setUnitOfWork(), getUnitOfWork() int-3Getter 和 setter method for the org.apache.camel.spi.UnitOfWork an 属性。这个属性只适用于参与事务的交换。
  • setExchangeId(), getExchangeId() abrt-abrtGetter 和 setter 方法用于交换 ID。自定义组件是否使用交换 ID 是实现详情。
  • addOnCompletion() Infoblox->_<Adds a org.apache.camel.spi.Synchronization 回调对象(在处理交换完成后会调用)。
  • 在所有 OnCompletion callback 对象到指定的交换对象上,handoverCompletions() abrt-abrt- the callbackHands on the all of the all of the all of the OnCompletion callback 对象。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat