第 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);
}
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(), have(), removePropertyProperties()有Properties()使用属性 setter 和 getter 方法将命名的属性与交换实例相关联。属性包含您的组件实施可能需要的其它元数据。 setIn(),getIn()Infoblox->_<Setter 和 getter 方法用于 In 消息。DefaultExchange类提供的实施实施 lazy creation语义:如果 In message 为 null,则getIn()DefaultExchange类会创建一个默认的 In 消息。setOut(),getOut(), , 具有Out()abrt- theSetter 和 getter 方法(用于 Out 消息)。-
setException(),getException()10.10.10.2- theGetter 和 setter 方法用于异常对象(元类型)。 -
对于因为异常或故障而失败的交换失败,则
isFailed()3.10.0--abrtRe returnstrue。 -
如果交换被转换,则
isTransacted()to the 时间为 to- the the Transli'strue。 -
如果交换被标记为回滚,则
isRollback()toRollback()to and-abrtRe returnstrue。 -
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 theorg.apache.camel.spi.UnitOfWorkan 属性。这个属性只适用于参与事务的交换。 -
setExchangeId(),getExchangeId()abrt-abrtGetter 和 setter 方法用于交换 ID。自定义组件是否使用交换 ID 是实现详情。 -
addOnCompletion()Infoblox->_<Adds aorg.apache.camel.spi.Synchronization回调对象(在处理交换完成后会调用)。 -
在所有 OnCompletion callback 对象到指定的交换对象上,
handoverCompletions()abrt-abrt- the callbackHands on the all of the all of the all of the OnCompletion callback 对象。