Inbound Gateway
入站网关支持入站通道适配器上的所有属性(除了“通道”被“请求通道”替换),加上一些其他属性。以下清单展示了可用的属性:
-
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 | 已转换消息发送到的消息通道。必需。 |
3 | 用于在接收 AMQP 消息时使用的 AmqpHeaderMapper`的引用。可选。默认情况下,仅将标准 AMQP 属性(如 `contentType )复制到和从 Spring Integration `MessageHeaders`中。AMQP `MessageProperties`中的任何用户定义 Header 均不会通过默认 `DefaultAmqpHeaderMapper`复制到 AMQP 消息中或从中复制出来。如果提供了“request-header-names”或“reply-header-names”则不允许。 |
4 | 从 AMQP 请求映射到 MessageHeaders`中 AMQP Header 的名称(以逗号分隔)。如果未提供“标头映射器”引用,则只能提供此属性。此列表中的值也可以是与标头名匹配的简单模式(例如 `"" or "thing1, thing2"`或 `"*thing1" )。 |
5 | 要映射到 AMQP 响应消息的 AMQP 消息属性中的 MessageHeaders`的名称(以逗号分隔)。所有标准 Header(如 `contentType )都映射到 AMQP 消息属性,而用户定义 Header 则映射到“header”属性。如果未提供“标头映射器”引用,则只能提供此属性。此列表中的值也可以是与标头名匹配的简单模式(例如 "" or "foo, bar"`或 `"*foo" )。 |
6 | 预期响应消息的消息通道。可选。 |
7 | 为基础 o.s.i.core.MessagingTemplate`设置 `receiveTimeout ,用于从响应通道接收消息。如果未指定,此属性默认为 1000 (1 秒)。仅适用于在发送响应之前,容器线程传递给另一个线程。 |
8 | 自定义的 `AmqpTemplate`bean 引用(以便更好地控制要发送的响应消息)。你可以为 `RabbitTemplate`提供备选实现。 |
9 | 当 requestMessage`没有 `replyTo`属性时,要使用的 `replyTo``o.s.amqp.core.Address 。如果未指定此选项,则不提供 amqp-template ,请求消息中没有 replyTo`属性,并且会引发 `IllegalStateException ,因为无法路由响应。如果没有指定此选项,并且提供了外部 amqp-template ,则不会引发任何异常。如果预计在请求消息中不存在 replyTo`属性,那么你必须指定此选项或在该模板上配置默认 `exchange`和 `routingKey 。 |
请参阅 Inbound Channel Adapter 中有关配置 listener-container
属性的注释。
从 5.5 版本开始,AmqpInboundChannelAdapter
可以用 org.springframework.amqp.rabbit.retry.MessageRecoverer
策略进行配置,该策略在内部调用重试操作时会在 RecoveryCallback
中使用。有关更多信息,请参阅 setMessageRecoverer()
JavaDoc。
Batched Messages
参见 Batched Messages。