Spring Integration - Reference

参考文档的这一部分快速介绍了 Spring Integration 项目中的 AMQP 支持。

This part of the reference documentation provides a quick introduction to the AMQP support within the Spring Integration project.

Introduction

Spring Integration 项目包括基于 Spring AMQP 项目的 AMQP 通道适配器和网关。这些适配器在 Spring Integration 项目中开发和发布。在 Spring Integration 中, “Channel Adapters” 是单向的,而 “Gateways” 是双向的(请求-响应)。我们提供一个入站通道适配器、一个出站通道适配器、一个入站网关和一个出站网关。

The Spring Integration project includes AMQP Channel Adapters and Gateways that build upon the Spring AMQP project. Those adapters are developed and released in the Spring Integration project. In Spring Integration, “Channel Adapters” are unidirectional (one-way), whereas “Gateways” are bidirectional (request-reply). We provide an inbound-channel-adapter, an outbound-channel-adapter, an inbound-gateway, and an outbound-gateway.

由于 AMQP 适配器是 Spring Integration 版本的一部分,因此文档作为 Spring Integration 发行版的一部分提供。我们在此简要概述主要功能。有关更多详细信息,请参见 Spring Integration Reference Guide

Since the AMQP adapters are part of the Spring Integration release, the documentation is available as part of the Spring Integration distribution. We provide a quick overview of the main features here. See the Spring Integration Reference Guide for much more detail.

Inbound Channel Adapter

要从队列接收 AMQP 消息,你可以配置一个 <inbound-channel-adapter>。以下示例展示了如何配置入站通道适配器:

To receive AMQP Messages from a queue, you can configure an <inbound-channel-adapter>. The following example shows how to configure an inbound channel adapter:

<amqp:inbound-channel-adapter channel="fromAMQP"
                              queue-names="some.queue"
                              connection-factory="rabbitConnectionFactory"/>

Outbound Channel Adapter

要将 AMQP 消息发送到交换,你可以配置一个 <outbound-channel-adapter>。除了交换名称之外,你还可以选择提供一个“路由密钥”。以下示例展示了如何定义出站通道适配器:

To send AMQP Messages to an exchange, you can configure an <outbound-channel-adapter>. You can optionally provide a 'routing-key' in addition to the exchange name. The following example shows how to define an outbound channel adapter:

<amqp:outbound-channel-adapter channel="toAMQP"
                               exchange-name="some.exchange"
                               routing-key="foo"
                               amqp-template="rabbitTemplate"/>

Inbound Gateway

若要接收队列中的 AMQP 消息并对其 reply-to 地址进行响应,您可以配置“<inbound-gateway>”。以下示例展示如何定义入站网关:

To receive an AMQP Message from a queue and respond to its reply-to address, you can configure an <inbound-gateway>. The following example shows how to define an inbound gateway:

<amqp:inbound-gateway request-channel="fromAMQP"
                      reply-channel="toAMQP"
                      queue-names="some.queue"
                      connection-factory="rabbitConnectionFactory"/>

Outbound Gateway

若要将 AMQP 消息发送到交换,并从远程客户端接收响应,您可以配置“<outbound-gateway>”。除了交换名称,还可以选择提供“路由密钥”。以下示例展示如何定义出站网关:

To send AMQP Messages to an exchange and receive back a response from a remote client, you can configure an <outbound-gateway>. You can optionally provide a 'routing-key' in addition to the exchange name. The following example shows how to define an outbound gateway:

<amqp:outbound-gateway request-channel="toAMQP"
                       reply-channel="fromAMQP"
                       exchange-name="some.exchange"
                       routing-key="foo"
                       amqp-template="rabbitTemplate"/>