【发布时间】:2019-03-27 23:40:12
【问题描述】:
我正在使用:
- SpringBoot 2.0.4
- ActiveMQ 5.15.5
- Apache Camel 2.22.0
- Java 1.8
- 时髦的
- 马文
基本上,我有一个带有 Apache Camel 路由的 SpringBoot 应用程序,该路由使用来自 ActiveMQ 的带有事务的消息。我需要在 ActiveMQ 上设置一个 RedeliveryPolicy,所以当处理发生错误时,消息会重试多次。
我为 ActiveMQ 制作了一个带有 bean 的配置类,事务按预期工作,但 RedeliveryPolicy 不起作用。有人可以帮我理解这有什么问题吗?
这是产生错误的消息的日志输出:
2018-10-23 10:35:28.005 调试 10524 --- [mer[entryQueue]] oacsspi.TransactionErrorHandler : 事务开始 (0x35d60381) 为 (MessageId: ID:EPIC-LAP-25- 50304-1540306817804-4:3:1:1:2 在 ExchangeId: ID-EPIC-LAP-25-1540312510586-0-1)) 2018-10-23 10:35:28.020 调试 10524 --- [mer[entryQueue]] o.apache.camel.processor.SendProcessor : >>>> direct://middle Exchange[ID-EPIC-LAP-25- 1540312510586-0-1] 2018-10-23 10:35:28.375 DEBUG 10524 --- [mer[entryQueue]] oacamel.processor.DefaultErrorHandler:(MessageId:ID:EPIC-LAP-25-50304-1540306817804-4:3: ExchangeId 上的 1:1:2:ID-EPIC-LAP-25-1540312510586-0-1)。交付尝试:0 捕获:java.lang.RuntimeException:ExceptionTest:订单失败 2018-10-23 10:35:28.390 错误 10524 --- [mer[entryQueue]] oacamel.processor.DefaultErrorHandler:(MessageId:ID:EPIC-LAP-25-50304-1540306817804-4:3: ExchangeId 上的 1:1:2:ID-EPIC-LAP-25-1540312510586-0-1)。交付尝试后用尽:1 捕获:java.lang.RuntimeException: ExceptionTest: Order Failed
这是我的 ActiveMQ 配置类:
import org.apache.activemq.ActiveMQConnectionFactory
import org.apache.activemq.RedeliveryPolicy
import org.apache.activemq.camel.component.ActiveMQComponent
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.jms.connection.JmsTransactionManager
import javax.jms.DeliveryMode
@Configuration
class ActiveMQConfiguration {
@Bean
ActiveMQConnectionFactory activeMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory()
activeMQConnectionFactory.brokerURL = 'tcp://localhost:61616'
activeMQConnectionFactory.userName = 'admin'
activeMQConnectionFactory.password = 'admin'
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy()
redeliveryPolicy.maximumRedeliveries = 3
redeliveryPolicy.redeliveryDelay = 150L
redeliveryPolicy.useExponentialBackOff = true
redeliveryPolicy.backOffMultiplier = 1.5
activeMQConnectionFactory.setRedeliveryPolicy(redeliveryPolicy)
activeMQConnectionFactory
}
@Bean
ActiveMQComponent activeMQComponent(@Qualifier('activeMQConnectionFactory')ActiveMQConnectionFactory activeMQConnectionFactory) {
ActiveMQComponent activeMQComponent = new ActiveMQComponent()
activeMQComponent.connectionFactory = activeMQConnectionFactory
activeMQComponent.transacted = true
activeMQComponent.transactionManager = txManager()
activeMQComponent.cacheLevelName = 'CACHE_CONSUMER'
activeMQComponent.lazyCreateTransactionManager = false
activeMQComponent.deliveryMode = DeliveryMode.PERSISTENT
activeMQComponent
}
@Bean
JmsTransactionManager txManager(@Qualifier('activeMQConnectionFactory') ActiveMQConnectionFactory activeMQConnectionFactory) {
JmsTransactionManager txManager = new JmsTransactionManager()
txManager.connectionFactory = activeMQConnectionFactory
txManager.rollbackOnCommitFailure = true
txManager
}
}
【问题讨论】:
标签: java spring-boot groovy apache-camel activemq