本节介绍 Spring Integration 提供的各种通道适配器和消息传递网关,以支持与外部系统的基于消息的通信。
每个系统,从 AMQP 到 Zookeeper,都有自己的集成需求,本节将介绍它们。
端点快速参考表
正如前面部分所讨论的,Spring Integration 提供了许多端点,用于与外部系统、文件系统和其他系统交互。
对于透明的依赖管理,Spring Integration 提供了一个要导入到 Maven 配置中的材料清单 POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>5.5.13</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
回顾一下:
-
入站通道适配器用于单向集成,以将数据带入消息传递应用程序。
-
出站通道适配器用于单向集成,以将数据从消息传递应用程序中发送出去。
-
入站网关用于双向集成流,其中一些其他系统调用消息传递应用程序并接收回复。
-
出站网关用于双向集成流,其中消息传递应用程序调用一些外部服务或实体并期望结果。
下表总结了各种端点以及相应章节的快速链接。
模块 | 入站适配器 | 出站适配器 | 入站网关 | 出站网关 |
---|---|---|---|---|
AMQP |
||||
活动 |
ñ |
ñ |
||
喂养 |
ñ |
ñ |
ñ |
|
文件 |
ñ |
|||
FTP(S) |
ñ |
|||
宝石火 |
ñ |
ñ |
||
HTTP |
||||
JDBC |
ñ |
|||
管理系统 |
||||
JMX |
ñ |
|||
JPA |
ñ |
|||
阿帕奇卡夫卡 |
||||
邮件 |
ñ |
ñ |
||
MongoDB |
ñ |
ñ |
||
MQTT |
ñ |
ñ |
||
R2DBC |
ñ |
ñ |
||
雷迪斯 |
Redis 入站通道适配器,Redis 队列入站通道适配器,Redis 存储入站通道适配器,Redis 流入站通道适配器 |
Redis 出站通道适配器,Redis 队列出站通道适配器,RedisStore 出站通道适配器,Redis 流出站通道适配器 |
||
资源 |
ñ |
ñ |
ñ |
|
RMI |
ñ |
ñ |
||
RSocket |
ñ |
ñ |
||
SFTP |
ñ |
|||
跺脚 |
ñ |
ñ |
||
溪流 |
ñ |
ñ |
||
系统日志 |
ñ |
ñ |
ñ |
|
TCP |
||||
UDP |
ñ |
ñ |
||
WebFlux |
||||
网页服务 |
ñ |
ñ |
||
网络套接字 |
ñ |
ñ |
||
XMPP |
ñ |
ñ |
||
零MQ |
ñ |
ñ |
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.
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.