入站网关
入站网关支持入站通道适配器的所有属性(除了 'channel' 被 'request-channel' 替换之外),还支持一些附加属性。以下列表显示了可用属性
-
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 中以及从其中复制。默认的 DefaultAmqpHeaderMapper 不会将 AMQP MessageProperties 中的任何用户自定义头复制到 AMQP 消息或从中复制。如果提供了 'request-header-names' 或 'reply-header-names',则不允许此属性。 |
4 | 要从 AMQP 请求映射到 MessageHeaders 的 AMQP 头名称的逗号分隔列表。仅在未提供 'header-mapper' 引用时才能提供此属性。此列表中的值也可以是与头名称匹配的简单模式(例如 "*" 或 "thing1*, thing2" 或 "*thing1" )。 |
5 | 要映射到 AMQP 回复消息的 AMQP 消息属性中的 MessageHeaders 名称的逗号分隔列表。所有标准头(如 contentType )都映射到 AMQP Message Properties,而用户定义的头则映射到 'headers' 属性。仅在未提供 'header-mapper' 引用时才能提供此属性。此列表中的值也可以是与头名称匹配的简单模式(例如 "*" 或 "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 。 |
请参阅入站通道适配器中关于配置 listener-container
属性的注意事项。
从版本 5.5 开始,AmqpInboundChannelAdapter
可以配置一个 org.springframework.amqp.rabbit.retry.MessageRecoverer
策略,该策略在内部调用重试操作时用于 RecoveryCallback
。有关更多信息,请参阅 setMessageRecoverer()
的 JavaDocs。
批量消息
请参阅批量消息。