Spring integration spring amqp死信队列不适用于事务
当ChannelTransacticedTrue发生错误而不是重新请求时,如何设置侦听器容器以将消息抛出死信队列?当我不使用ChannelTransact时,一切正常,我可以在死信队列中看到消息Spring integration spring amqp死信队列不适用于事务,spring-integration,spring-amqp,spring-integration-dsl,Spring Integration,Spring Amqp,Spring Integration Dsl,当ChannelTransacticedTrue发生错误而不是重新请求时,如何设置侦听器容器以将消息抛出死信队列?当我不使用ChannelTransact时,一切正常,我可以在死信队列中看到消息 @Bean(name = "amqpInboundEsignRequest") public IntegrationFlow amqpInbound(ConnectionFactory connectionFactory, PlatformTransactionManager transactionMa
@Bean(name = "amqpInboundEsignRequest")
public IntegrationFlow amqpInbound(ConnectionFactory connectionFactory, PlatformTransactionManager transactionManager) {
return IntegrationFlows.from(
Amqp.inboundAdapter(connectionFactory, esignIAutoRequestQueue())
.acknowledgeMode(AcknowledgeMode.AUTO)
.messageConverter(new Jackson2JsonMessageConverter())
.autoStartup(false)
.defaultRequeueRejected(false)
//.channelTransacted(true) // dead letter does not work
//.transactionManager(transactionManager) // dead letter does not work
)
.log("amqpInbound.start-process")
.handle(p -> {
throw new RuntimeException("Something wrong!");
})
.get();
}
编辑
这些是依赖项的版本
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:1.5.9.RELEASE:compile
[INFO] | +- org.springframework:spring-messaging:jar:4.3.13.RELEASE:compile
[INFO] | \- org.springframework.amqp:spring-rabbit:jar:1.7.4.RELEASE:compile
[INFO] | +- com.rabbitmq:http-client:jar:1.1.1.RELEASE:compile
[INFO] | +- com.rabbitmq:amqp-client:jar:4.0.3:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.2.1.RELEASE:compile
[INFO] | \- org.springframework.amqp:spring-amqp:jar:1.7.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-integration:jar:1.5.9.RELEASE:compile
[INFO] | +- org.springframework.integration:spring-integration-core:jar:4.3.12.RELEASE:compile
[INFO] | \- org.springframework.integration:spring-integration-java-dsl:jar:1.2.3.RELEASE:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.0:compile
我想让事务与外部事务db PlatformTransactionManager同步。当我在侦听器容器上设置TransactionManager TransactionManager时,它总是执行requeue。您使用的是什么版本?我刚刚用Spring Integration 5.0.2和Spring AMQP 2.0.2,以及Spring Integration 4.3.14和Spring AMQP 1.7.6测试了ChannelTransact=true,一切正常,失败的消息传到了DLQ
@SpringBootApplication
public class So48914749Application {
public static void main(String[] args) {
SpringApplication.run(So48914749Application.class, args);
}
@Bean
public IntegrationFlow amqpInbound(ConnectionFactory connectionFactory) {
return IntegrationFlows.from(
Amqp.inboundAdapter(connectionFactory, "foo")
.acknowledgeMode(AcknowledgeMode.AUTO)
.messageConverter(new Jackson2JsonMessageConverter())
.autoStartup(true)
.defaultRequeueRejected(false)
.channelTransacted(true) // dead letter does not work
// .transactionManager(transactionManager) // dead letter does not work
)
.log("amqpInbound.start-process")
.handle(p -> {
throw new RuntimeException("Something wrong!");
})
.get();
}
@Bean
public Queue queue() {
return QueueBuilder.durable("foo")
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", "dlq")
.build();
}
@Bean
public Queue dlq() {
return new Queue("dlq");
}
@RabbitListener(queues = "dlq")
public void dlq(Message in) {
System.out.println(in);
}
}
结果:
正文:'[B@17793549byte[8] 'MessageProperties[headers={x-first-death-exchange=,x-death=[{reason=rejected,count=1,exchange=,time=Wed Feb 21 16:43:48 EST 2018,routing keys=[foo],queue=foo}],x-first-death-reason=rejected,x-first-death-queue=foo},timestamp=null,messageId=null,userId=null,receivedUserId=null,appId=null,clusterId=null,type=null,correlationId=null,correlationIdString=null,replyTo=null,contentType=null,contentEncoding=null,contentLength=0,deliveryMode=null,receivedDeliveryMode=NON\u PERSISTENT,expiration=null,priority=null,redelivered=false,receivedExchange=,ReceivedLotingKey=dlq,receivedDelay=null,deliveryTag=4,messageCount=0,consumerTag=amq.ctag-DOYPXDKQ5HVW2W9CUIPZG,consumerQueue=dlq]
编辑
以后请更准确;您的问题意味着无论是否提供了事务管理器,都会出现相同的问题 请参阅。这在2.0中已修复 在1.7.x中,为了向后兼容,我们必须在默认情况下保留旧行为。说明必须将alwaysRequeueWithTxManagerRollback设置为false,以获取新的一致性行为
这是一个侦听器容器属性,因此您需要连接一个容器并将其插入入站通道适配器。感谢您的快速响应。我更新了我的问题。请以后更准确一些;您的问题意味着无论是否提供了事务管理器,都会出现相同的问题。我为我的错误道歉非常准确的信息。非常感谢。它现在工作得很好