Spring integration 如何为spring集成流添加try-catch异常以实现嵌套事务
如何在spring集成流中处理嵌套事务。基本上,我有一个从数据库中获取所有订单的流程,并按订单进行处理,在单个订单上抛出异常的情况下,所有处理的订单都会回滚Spring integration 如何为spring集成流添加try-catch异常以实现嵌套事务,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,如何在spring集成流中处理嵌套事务。基本上,我有一个从数据库中获取所有订单的流程,并按订单进行处理,在单个订单上抛出异常的情况下,所有处理的订单都会回滚 IntegrationFlows.from("perOrder") .filter(Order.class, order -> order.getItems().size() > 0) .handle(orderHandler, "handle") /*someway i way wa
IntegrationFlows.from("perOrder")
.filter(Order.class, order -> order.getItems().size() > 0)
.handle(orderHandler, "handle") /*someway i way want to add try/catch for this method here so that
if handle method throws exception, want to suppress for that order and mark as failure only for that order */
.get();
public class OrderHandler {
@Transactional(propagation = Propagation.NESTED)
public handle() {
processing code
throw exception in case of any validation failure
}
}
为此,我们提供了一个adviceChain,该adviceChain将注入该
句柄()的端点中:
.handle((GenericHandler)(p,h)->{
抛出新的RuntimeException(“故意”);
},e->e.advice(retryAdvice())
您可以在那里插入任何可用的建议
实现:,包括TransactionInterceptor
:
使用try…catch语义的最好方法是使用表达式evaluationRequestHandlerAdvice
。在文档和JavaDocs中查看它的描述。谢谢,我将尝试上面提到的选项
.handle((GenericHandler<?>) (p, h) -> {
throw new RuntimeException("intentional");
}, e -> e.advice(retryAdvice()))