Inbound Gateway
入站网关支持入站通道适配器上的所有属性(除了“通道”被“请求通道”替换),加上一些其他属性。以下清单展示了可用的属性:
The inbound gateway supports all the attributes on the inbound channel adapter (except that 'channel' is replaced by 'request-channel'), plus some additional attributes. The following listing shows the available attributes:
-
Java DSL
-
Java
-
XML
@Bean // return the upper cased payload
public IntegrationFlow amqpInboundGateway(ConnectionFactory connectionFactory) {
return IntegrationFlow.from(Amqp.inboundGateway(connectionFactory, "foo"))
.transform(String.class, String::toUpperCase)
.get();
}
@Bean
public MessageChannel amqpInputChannel() {
return new DirectChannel();
}
@Bean
public AmqpInboundGateway inbound(SimpleMessageListenerContainer listenerContainer,
@Qualifier("amqpInputChannel") MessageChannel channel) {
AmqpInboundGateway gateway = new AmqpInboundGateway(listenerContainer);
gateway.setRequestChannel(channel);
gateway.setDefaultReplyTo("bar");
return gateway;
}
@Bean
public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
SimpleMessageListenerContainer container =
new SimpleMessageListenerContainer(connectionFactory);
container.setQueueNames("foo");
container.setConcurrentConsumers(2);
// ...
return container;
}
@Bean
@ServiceActivator(inputChannel = "amqpInputChannel")
public MessageHandler handler() {
return new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return "reply to " + requestMessage.getPayload();
}
};
}
<int-amqp:inbound-gateway
id="inboundGateway" 1
request-channel="myRequestChannel" 2
header-mapper="" 3
mapped-request-headers="" 4
mapped-reply-headers="" 5
reply-channel="myReplyChannel" 6
reply-timeout="1000" 7
amqp-template="" 8
default-reply-to="" /> 9
1 | 此适配器的唯一 ID。可选。 |
2 | The Unique ID for this adapter. Optional. |
3 | 已转换消息发送到的消息通道。必需。 |
4 | Message channel to which converted messages are sent. Required. |
5 | 用于在接收 AMQP 消息时使用的 AmqpHeaderMapper`的引用。可选。默认情况下,仅将标准 AMQP 属性(如 `contentType )复制到和从 Spring Integration `MessageHeaders`中。AMQP `MessageProperties`中的任何用户定义 Header 均不会通过默认 `DefaultAmqpHeaderMapper`复制到 AMQP 消息中或从中复制出来。如果提供了“request-header-names”或“reply-header-names”则不允许。 |
6 | A reference to an AmqpHeaderMapper to use when receiving AMQP Messages.
Optional.
By default, only standard AMQP properties (such as contentType ) are copied to and from Spring Integration MessageHeaders .
Any user-defined headers within the AMQP MessageProperties are not copied to or from an AMQP message by the default DefaultAmqpHeaderMapper .
Not allowed if 'request-header-names' or 'reply-header-names' is provided. |
7 | 从 AMQP 请求映射到 MessageHeaders`中 AMQP Header 的名称(以逗号分隔)。如果未提供“标头映射器”引用,则只能提供此属性。此列表中的值也可以是与标头名匹配的简单模式(例如 `"" or "thing1, thing2"`或 `"*thing1" )。 |
8 | Comma-separated list of names of AMQP Headers to be mapped from the AMQP request into the MessageHeaders .
This attribute can be provided only if the 'header-mapper' reference is not provided.
The values in this list can also be simple patterns to be matched against the header names (e.g. "" or "thing1, thing2" or "*thing1" ). |
9 | 要映射到 AMQP 响应消息的 AMQP 消息属性中的 MessageHeaders`的名称(以逗号分隔)。所有标准 Header(如 `contentType )都映射到 AMQP 消息属性,而用户定义 Header 则映射到“header”属性。如果未提供“标头映射器”引用,则只能提供此属性。此列表中的值也可以是与标头名匹配的简单模式(例如 "" or "foo, bar"`或 `"*foo" )。 |
10 | Comma-separated list of names of MessageHeaders to be mapped into the AMQP message properties of the AMQP reply message.
All standard Headers (such as contentType ) are mapped to AMQP Message Properties, while user-defined headers are mapped to the 'headers' property.
This attribute can only be provided if the 'header-mapper' reference is not provided.
The values in this list can also be simple patterns to be matched against the header names (for example, "" or "foo, bar" or "*foo" ). |
11 | 预期响应消息的消息通道。可选。 |
12 | Message Channel where reply Messages are expected. Optional. |
13 | 为基础 o.s.i.core.MessagingTemplate`设置 `receiveTimeout ,用于从响应通道接收消息。如果未指定,此属性默认为 1000 (1 秒)。仅适用于在发送响应之前,容器线程传递给另一个线程。 |
14 | Sets the receiveTimeout on the underlying o.s.i.core.MessagingTemplate for receiving messages from the reply channel.
If not specified, this property defaults to 1000 (1 second).
Only applies if the container thread hands off to another thread before the reply is sent. |
15 | 自定义的 `AmqpTemplate`bean 引用(以便更好地控制要发送的响应消息)。你可以为 `RabbitTemplate`提供备选实现。 |
16 | The customized AmqpTemplate bean reference (to have more control over the reply messages to send).
You can provide an alternative implementation to the RabbitTemplate . |
17 | 当 requestMessage`没有 `replyTo`属性时,要使用的 `replyTo``o.s.amqp.core.Address 。如果未指定此选项,则不提供 amqp-template ,请求消息中没有 replyTo`属性,并且会引发 `IllegalStateException ,因为无法路由响应。如果没有指定此选项,并且提供了外部 amqp-template ,则不会引发任何异常。如果预计在请求消息中不存在 replyTo`属性,那么你必须指定此选项或在该模板上配置默认 `exchange`和 `routingKey 。 |
18 | The replyTo o.s.amqp.core.Address to be used when the requestMessage does not have a replyTo
property.
If this option is not specified, no amqp-template is provided, no replyTo property exists in the request message, and
an IllegalStateException is thrown because the reply cannot be routed.
If this option is not specified and an external amqp-template is provided, no exception is thrown.
You must either specify this option or configure a default exchange and routingKey on that template,
if you anticipate cases when no replyTo property exists in the request message. |
请参阅 Inbound Channel Adapter 中有关配置 listener-container
属性的注释。
See the note in Inbound Channel Adapter about configuring the listener-container
attribute.
从 5.5 版本开始,AmqpInboundChannelAdapter
可以用 org.springframework.amqp.rabbit.retry.MessageRecoverer
策略进行配置,该策略在内部调用重试操作时会在 RecoveryCallback
中使用。有关更多信息,请参阅 setMessageRecoverer()
JavaDoc。
Starting with version 5.5, the AmqpInboundChannelAdapter
can be configured with an org.springframework.amqp.rabbit.retry.MessageRecoverer
strategy which is used in the RecoveryCallback
when the retry operation is called internally.
See setMessageRecoverer()
JavaDocs for more information.
Batched Messages
参见 Batched Messages。
See Batched Messages.