Integration Endpoints
本节介绍 Spring Integration 提供的各种通道适配器和消息网关,以支持与外部系统进行基于消息的通信。
This section covers the various channel adapters and messaging gateways provided by Spring Integration to support message-based communication with external systems.
从 AMQP 到 Zookeeper,每个系统都有其自己的集成要求,本节涵盖了这些要求。
Each system, from AMQP to Zookeeper, has its own integration requirements, and this section covers them.
Endpoint Quick Reference Table
如前几节所述,Spring Integration 提供了许多端点,用于与外部系统、文件系统等进行接口。
As discussed in the earlier sections, Spring Integration provides a number of endpoints used to interface with external systems, file systems, and others.
对于透明的依赖管理,Spring Integration 提供了一个物料清单 POM,用于导入 Maven 配置:
For transparent dependency management Spring Integration provides a bill-of-materials POM to be imported into the Maven configuration:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>{project-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
回顾一下:
To recap:
-
Inbound channel adapters are used for one-way integration to bring data into the messaging application.
-
Outbound channel adapters are used for one-way integration to send data out of the messaging application.
-
Inbound gateways are used for a bidirectional integration flow, where some other system invokes the messaging application and receives a reply.
-
Outbound Gateways are used for a bidirectional integration flow, where the messaging application invokes some external service or entity and expects a result.
下表总结了各种端点,并提供了指向相应章节的快速链接。
The following table summarizes the various endpoints with quick links to the appropriate chapter.
此外,正如 Core Messaging 中讨论的那样,Spring Integration 提供了用于连接普通旧 Java 对象 (POJO) 的端点。正如 Channel Adapter 中所讨论的那样,<int:inbound-channel-adapter>
元素允许您轮询 Java 方法以获取数据。<int:outbound-channel-adapter>
元素允许您将数据发送到 void
方法。正如 Messaging Gateways 所讨论的那样,<int:gateway>
元素允许任何 Java 程序调用消息流。这些每个都可以使用而不需要对 Spring Integration 具有任何源级别依赖项。在这种情况下,出站网关的等效项是使用服务激活器(请参见 Service Activator)调用返回某种 Object
的方法。
In addition, as discussed in Core Messaging, Spring Integration provides endpoints for interfacing with Plain Old Java Objects (POJOs).
As discussed in Channel Adapter, the <int:inbound-channel-adapter>
element lets you poll a Java method for data.
The <int:outbound-channel-adapter>
element lets you send data to a void
method.
As discussed in Messaging Gateways, the <int:gateway>
element lets any Java program invoke a messaging flow.
Each of these works without requiring any source-level dependencies on Spring Integration.
The equivalent of an outbound gateway in this context is using a service activator (see Service Activator) to invoke a method that returns an Object
of some kind.
从版本 5.2.2
开始,所有入站网关都可以使用 errorOnTimeout
布尔标记进行配置,以便在下游流在应答超时期间未返回应答时抛出 MessageTimeoutException
。该计时器在该线程返回对网关的控制权之前不会启动,因此通常只在异步下游流时或在下游流因某些处理程序(例如 filter)返回 null
而停止时才起作用。该异常可以在 errorChannel
流中得到处理,例如,为请求客户端生成补偿应答。
Starting with version 5.2.2
, all the inbound gateways can be configured with an errorOnTimeout
boolean flag to throw a MessageTimeoutException
when the downstream flow doesn’t return a reply during the reply timeout.
The timer is not started until the thread returns control to the gateway, so usually it is only useful when the downstream flow is asynchronous, or it stops because of a null
return from some handler, e.g. filter.
Such an exception can be handled on the errorChannel
flow, e.g. producing a compensation reply for requesting client.