2.4 Message Endpoints
A Message Endpoint represents the "filter" of a pipes-and-filters architecture. As mentioned above(如上所述), the endpoint's primary role is to connect application code to the messaging framework and to do so in a non-invasive manner(非侵入的). In other words, the application code should ideally have no awareness(意识) of the Message objects or the Message Channels. This is similar to the role of a Controller in the MVC paradigm. Just as a Controller handles HTTP requests, the Message Endpoint handles Messages. Just as Controllers are mapped to URL patterns, Message Endpoints are mapped to Message Channels. The goal is the same in both cases: isolate(隔离) application code from the infrastructure. These concepts are discussed at length along with all of the patterns that follow in the Enterprise Integration Patterns book. Here, we provide only a high-level description of the main endpoint types supported by Spring Integration and their roles. The chapters that follow will elaborate and provide sample code as well as configuration examples.
消息末端 充当 pipes-and-filters 体系中的 filter角色,正如上文提到的,他主要职责以一种 非侵入的方式连接应用层与消息框架的实现。换一种方式描述,应用层无需太多考虑消息本身或者消息通道。 这个角色类似与MVC模式下的Controller层所提供的功能。而Controller仅仅用于处理HTTP requests,而HTTP requestsMessage Endpoint 处理Message。Controllers提供针对URL的映射机制,Message Endpoints提供针对channel的映射机制。 但是他们具有共同的目标:从消息框架中隔离应用层代码。接下来的章节会用较长的文字来描述相关细节。但是更多的细节请参考 Enterprise Integration Patterns 一书。在这里我们仅仅提供一个大概的与Spring Integration想关的概念解释。同时,接下来的章节 会提供一些代码实例。
2.4.1 Transformer
A Message Transformer(改造器) is responsible for converting a Message's content or structure and returning the modified Message. Probably the most common type of transformer is one that converts the payload of the Message from one format to another (e.g. from XML Document to java.lang.String). Similarly, a transformer may be used to add, remove, or modify the Message's header values.
(PS:协议转换器:提供转换消息格式以及内容的功能,大多数的协议转换器用于格式化消息,例如把一个Xml格式的消息 转换为String消息,同时,协议转换器还可以对消息头的信息进行修改。)
2.4.2 Filter
A Message Filter determines(决定) whether a Message should be passed to(被传递到) an output channel at all. This simply requires a boolean test method that may check for a particular payload content type, a property value, the presence of a header, etc. If the Message is accepted, it is sent to the output channel, but if not it will be dropped (or for a more severe implementation, an Exception could be thrown). Message Filters are often used in conjunction(关联) with a Publish Subscribe channel, where multiple consumers may receive the same Message and use the filter to narrow down the set of Messages to be processed based on some criteria.
(PS:消息过滤器 用于判断一个消息是否可以被流转到另外一个输出channl。他需要一个通过判断消息体中 中的负载内容、一个属性值或者消息头中的某一属性是否满足指定的调教,从而返回一个简单的boolean值 来决定。一旦返回为true,则消息允许流转到下一个输出channel中。反之则被丢弃(或者抛出一个异常信息)。 消息过滤器常被用于连接 广播/订阅 模式的通道下,用于对广播的消息进行有效过滤。从而只获取与自己业务相关 的消息进一步进行处理。 )
Be careful not to confuse (混淆) the generic use of "filter" within the Pipes-and-Filters architectural pattern with this specific endpoint type that selectively narrows down the Messages flowing between two channels. The Pipes-and-Filters concept of "filter" matches more closely with Spring Integration's Message Endpoint: any component that can be connected to Message Channel(s) in order to send and/or receive Messages.(PS:注意:不要混淆这里所描述的"filter" 与 Pipes-and-Filters 体系中的 Filters。 这里的"filter" 是相对狭义的,仅只两个channel之间的消息过滤组件。 Pipes-and-Filters 中 "filter"概念是,与Spring Integration紧密想关的Message Endpoint:任何组件都可以通过 Message Endpoint接入 消息通道进行消息的收发。)
2.4.3 Router
A Message Router is responsible for deciding(决定) what channel or channels should receive the Message next (if any). Typically the decision is based upon the Message's content and/or metadata available in the Message Headers. A Message Router is often used as a dynamic alternative(选 择) to a statically configured output channel on a Service Activator or other endpoint capable of sending reply Messages. Likewise, a Message Router provides a proactive alternative to the reactive Message Filters used by multiple subscribers as described above.
(PS: 消息路由器 提供判断消息流向那个channel 的功能,通过对消息内容或者消息元数据 判断,从而决定下一个需要流向的channel。消息路由器用于动态选择已经配置好的输出channel通过 Service Activator或者其他具有发送响应消息的Messages,同样,消息路由器也常被使用与替代订阅通道使用。 他能够前提对消息进行分发)
2.4.4 Splitter
A Splitter is another type of Message Endpoint whose responsibility is to accept a Message from its input channel, split that Message into multiple Messages, and then send each of those to its output channel. This is typically used for dividing a "composite" payload object into a group of Messages containing the sub-divided payloads.
(PS:这个章节主要是描述 对消息有效负载的一个分包处理,由于这一块我都没整明白,翻译的主要来自google, 消息分包器 对于来自输入通道的消息进行分包处理。然后分别发送到输出通道。 这通常是用于“复合”的有效载荷对象划分为一组信息,包括细分的有效载荷。)
2.4.5 Aggregator
Basically a mirror-image of the Splitter, the Aggregator is a type of Message Endpoint that receives multiple Messages and combines them into a single Message. In fact, Aggregators are often downstream consumers in a pipeline that includes a Splitter. Technically, the Aggregator is more complex than a Splitter, because it is required to maintain state (the Messages to-be-aggregated), to decide when the complete group of Messages is available, and to timeout if necessary. Furthermore, in case of a timeout, the Aggregator needs to know whether to send the partial results or to discard them to a separate channel. Spring Integration provides aCompletionStrategyas well as configurable settings for timeout, whether to send partial results upon timeout, and the discard channel.
(PS:针对分发器分发的镜像包,聚合器就是针对这些分发的报文进行组装,还原为一条完整的消息。事实上, 聚合器常使用与配置Splitter的下游的channel中。他需要维持被切割的不完整的报文,直到整个完成消息到达。 他支持 消息超时 设置,后面翻译来自google urthermore,在超时的情况下,聚合需要知道是否要发送的部分结果,或将其丢弃到一个单独的通道。 Spring 集成提供了一个的CompletionStrategy以及可配置的超时设置,是否超时后,和丢包信道发送的部分结果。)
2.4.6 Service Activator
A Service Activator is a generic endpoint for connecting a service instance to the messaging system.(一个服务激活是一个通用的端点连接服务实例的消息传递系 统。) The input Message Channel must be configured, and if the service method to be invoked is capable of returning a value, an output Message Channel may also be provided.
(PS:Service Activator 是一个比较通用的endpoint统称,该组件主要用于连接一个消息传输舒服实例。 该组件必须配置 输入channel。当一个service 的方法被调用可以返回一个值。另外该组件支持配置 输出channel)
The output channel is optional, since each Message may also provide its own 'Return Address' header. This same rule applies for all consumer endpoints.(PS:注意,输出通道是可选的,因为每个消息可以提供自己的返回地址通过消息头的元数据描述信息。 这个规则也适用与其他任何消费型的endpoints)
The Service Activator invokes an operation on some service object to process the request Message, extracting(提取) the request Message's payload and converting if necessary (if the method does not expect a Message-typed parameter). Whenever the service object's method returns a value, that return value will likewise be converted to a reply Message if necessary (if it's not already a Message). That reply Message is sent to the output channel. If no output channel has been configured, then the reply will be sent to the channel specified in the Message's "return address" if available.
(PS:Service Activator调用服务端一个指定的操作来处理消息,从中提供请求消息的有效负载并且提供 消息类型转换功能。当服务端方法返回一个值,该值同样被转换为响应消息(或者输出到配置输出channel的通道中。 如果没有配置输出通道,他将尝试输出到消息头指定的响应者的地址上。))

2.4.7 Channel Adapter
A Channel Adapter is an endpoint that connects a Message Channel to some other system or transport. Channel Adapters may be either inbound or outbound. Typically, the Channel Adapter will do some mapping between the Message and whatever object or resource is received-from or sent-to the other system (File, HTTP Request, JMS Message, etc). Depending on the transport, the Channel Adapter may also populate or extract Message header values. Spring Integration provides a number of Channel Adapters, and they will be described in upcoming chapters.
(PS:Channel Adapter 主要实现消息通道与其他系统之间的连接。 适配器分对内与对外两种,一般而言,Channel Adapter提供消息与实体系统你哦个[File, HTTP Request, JMS] 之间的发送或者接收映射。按照传输,Channel Adapter同样可以填充以及修改消息Header的中的值。 Spring Integration 提供了种类繁多的适配器,会在之后的章节中介绍。)

An inbound "Channel Adapter" endpoint connects a source system to a MessageChannel.
An outbound "Channel Adapter" endpoint connects a MessageChannel to a target system.