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.

Table 1. Endpoint Quick Reference
Module Inbound Adapter Outbound Adapter Inbound Gateway Outbound Gateway

AMQP

Inbound Channel Adapter

Outbound Channel Adapter

Inbound Gateway

Outbound Gateway

Apache Camel

N

Outbound Channel Adapter

N

Outbound Gateway

Apache Cassandra

N

Outbound Channel Adapter

N

Outbound Gateway

Debezium

Debezium Inbound Channel Adapter

N

N

N

Events

Receiving Spring Application Events

Sending Spring Application Events

N

N

Feed

Feed Inbound Channel Adapter

N

N

N

File

Reading Files and 'tail’ing Files

Writing files

N

Writing files

FTP(S)

FTP Inbound Channel Adapter

FTP Outbound Channel Adapter

N

FTP Outbound Gateway

GraphQL

N

N

N

GraphQL Outbound Gateway

Hazelcast

Hazelcast Inbound Channel Adapter

Hazelcast Outbound Channel Adapter

N

N

HTTP

HTTP Namespace Support

HTTP Namespace Support

Http Inbound Components

HTTP Outbound Components

JDBC

Inbound Channel Adapter and Stored Procedure Inbound Channel Adapter

Outbound Channel Adapter and Stored Procedure Outbound Channel Adapter

N

Outbound Gateway and Stored Procedure Outbound Gateway

JMS

Inbound Channel Adapter and Message-driven Channel Adapter

Outbound Channel Adapter

Inbound Gateway

Outbound Gateway

JMX

Notification-listening Channel Adapter and Attribute-polling Channel Adapter and Tree-polling Channel Adapter

Notification-publishing Channel Adapter and Operation-invoking Channel Adapter

N

Operation-invoking Outbound Gateway

JPA

Inbound Channel Adapter

Outbound Channel Adapter

N

Updating Outbound Gateway and Retrieving Outbound Gateway

Apache Kafka

Message Driven Channel Adapter and Inbound Channel Adapter

Outbound Channel Adapter

Inbound Gateway

Outbound Gateway

Mail

Mail-receiving Channel Adapter

Mail-sending Channel Adapter

N

N

MongoDB

MongoDB Inbound Channel Adapter

MongoDB Outbound Channel Adapter

N

N

MQTT

Inbound (Message-driven) Channel Adapter

Outbound Channel Adapter

N

N

R2DBC

R2DBC Inbound Channel Adapter

R2DBC Outbound Channel Adapter

N

N

Redis

Redis Inbound Channel Adapter, Redis Queue Inbound Channel Adapter, Redis Store Inbound Channel Adapter, Redis Stream Inbound Channel Adapter

Redis Outbound Channel Adapter, Redis Queue Outbound Channel Adapter, RedisStore Outbound Channel Adapter, Redis Stream Outbound Channel Adapter

Redis Queue Inbound Gateway

Redis Outbound Command Gateway and Redis Queue Outbound Gateway

Resource

Resource Inbound Channel Adapter

N

N

N

RSocket

N

N

RSocket Inbound Gateway

RSocket Outbound Gateway

SFTP

SFTP Inbound Channel Adapter

SFTP Outbound Channel Adapter

N

SFTP Outbound Gateway

SMB

SMB Inbound Channel Adapter, SMB Streaming Inbound Channel Adapter

SMB Outbound Channel Adapter

N

SMB Outbound Gateway

STOMP

STOMP Inbound Channel Adapter

STOMP Outbound Channel Adapter

N

N

Stream

Reading from Streams

Writing to Streams

N

N

Syslog

Syslog Inbound Channel Adapter

N

N

N

TCP

TCP Adapters

TCP Adapters

TCP Gateways

TCP Gateways

UDP

UDP Adapters

UDP Adapters

N

N

WebFlux

WebFlux Inbound Channel Adapter

WebFlux Outbound Channel Adapter

Inbound WebFlux Gateway

Outbound WebFlux Gateway

Web Services

N

N

Inbound Web Service Gateways

Outbound Web Service Gateways

Web Sockets

WebSocket Inbound Channel Adapter

WebSocket Outbound Channel Adapter

N

N

XMPP

XMPP Messages and XMPP Presence

XMPP Messages and XMPP Presence

N

N

ZeroMQ

ZeroMQ Inbound Channel Adapter

ZeroMQ outbound Channel Adapter

N

N

此外,正如 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.