首页 > 解决方案 > org.springframework.integration.dsl.filter(...) 方法发生内部异常

问题描述

当运行时异常源自 org.springframework.integration.dsl.IntegrationFlowDefinition.filter(...) 方法的执行范围时,我们观察到 DLQ 消息在 RabbitMq 中缺少跟踪堆栈。

例如,使用以下代码片段:

@Bean
IntegrationFlow accountingMovementFlow(final Function<AccountingMovement, AccountingMovement> tranMoveMapValEnricher, final MessageChannel auditDiscardChannel, final Clock clock
) {
    return from("dltmvChannel")
            .transform(Message.class, message -> (Message<?>) MessageBuilder.fromMessage(message)
                    .setHeader(SINK_STARTED_TIMESTAMP, LocalDateTime.ofInstant(clock.instant(), ZoneId.of("UTC")).toString())
                    .build())

            .transform(new AccountingMovementMapper())
            .filter(AccountingMovement::isValidOperationType,
                    discardFlow -> discardFlow.discardChannel(auditDiscardChannel))
            .filter(AccountingMovement.class, accountingMovement -> accountingMovement.getAccountBusinessDate().isBefore(accountingMovement.getMovementEffectiveDate()),
                    discardFlow -> discardFlow.discardChannel(auditDiscardChannel))

            .transform(tranMoveMapValEnricher::apply)
            .filter(AccountingMovement.class, accountingMovement -> !accountingMovement.isExistingMovement(),
                    discardFlow -> discardFlow.discardChannel(auditDiscardChannel))

            .channel("accountingMovementEnricherChannel")
            .get();
}

假设 AccountBusinessDate 为空。执行accountingMovement.getAccountBusinessDate().isBefore(accountingMovement.getMovementEffectiveDate())会立即触发NullPointerException。在这种情况下,流入“dltmvChannel”的消息将存储在带有跟踪堆栈的 DLQ 中。然而,这并没有发生。

我们跟踪/调试了 .filter(...) 方法,发现内部执行实际上触发了另一个解析异常,因为原始运行时异常正在冒泡。因此,DLQ 的消息缺少跟踪堆栈。

我们在 org.springframework.integration.dsl.IntegrationFlowDefinition 的其他方法中看不到这种行为。例如,如果 tranMoveMapValEnricher::apply 在执行 org.springframework.integration.dsl.IntegrationFlowDefinition.transform(...) 时触发运行时异常,则该消息将使用跟踪堆栈进行 DLQ。

标签: javaspring-integrationspring-rabbitspring-integration-dsl

解决方案


推荐阅读