Spring Integration - 参考文档
参考文档的这一部分提供了对 Spring Integration 项目中 AMQP 支持的快速介绍。
介绍
Spring Integration 项目包含了基于 Spring AMQP 项目构建的 AMQP 通道适配器和网关。这些适配器是在 Spring Integration 项目中开发和发布的。在 Spring Integration 中,“通道适配器”是单向的(单方向),而“网关”是双向的(请求-响应)。我们提供了一个入站通道适配器(inbound-channel-adapter)、一个出站通道适配器(outbound-channel-adapter)、一个入站网关(inbound-gateway)和一个出站网关(outbound-gateway)。
由于 AMQP 适配器是 Spring Integration 发布的一部分,其文档也作为 Spring Integration 分发的一部分提供。我们在此对其主要功能进行简要概述。更多详细信息,请参阅 Spring Integration 参考指南。
入站通道适配器
要从队列接收 AMQP 消息,你可以配置一个 <inbound-channel-adapter>
。以下示例展示了如何配置一个入站通道适配器:
<amqp:inbound-channel-adapter channel="fromAMQP"
queue-names="some.queue"
connection-factory="rabbitConnectionFactory"/>
出站通道适配器
要将 AMQP 消息发送到交换机,你可以配置一个 <outbound-channel-adapter>
。除了交换机名称外,你还可以选择提供一个 routing-key
。以下示例展示了如何定义一个出站通道适配器:
<amqp:outbound-channel-adapter channel="toAMQP"
exchange-name="some.exchange"
routing-key="foo"
amqp-template="rabbitTemplate"/>
入站网关
要从队列接收 AMQP 消息并响应其回复地址,你可以配置一个 <inbound-gateway>
。以下示例展示了如何定义一个入站网关:
<amqp:inbound-gateway request-channel="fromAMQP"
reply-channel="toAMQP"
queue-names="some.queue"
connection-factory="rabbitConnectionFactory"/>
出站网关
要将 AMQP 消息发送到 exchange 并从远程客户端接收响应,你可以配置一个 <outbound-gateway>
。除了 exchange 名称外,你还可以选择提供一个 'routing-key'。以下示例展示了如何定义一个 outbound gateway:
<amqp:outbound-gateway request-channel="toAMQP"
reply-channel="fromAMQP"
exchange-name="some.exchange"
routing-key="foo"
amqp-template="rabbitTemplate"/>