Spring集成delayer- Jdbc消息存储:消息未被删除

时间:2017-07-22 14:44:53

标签: spring spring-integration

下面是我在我的应用程序中使用的延迟代码。输出通道checkMessageInProgress是一个数据库存储过程调用,它将检查是否需要处理或延迟消息。 如果需要再次延迟消息,则重试计数会递增。 3次延迟后,将引发自定义应用程序异常。我正在使用jdbc消息存储来获取延迟消息。在消息延迟3次并引发异常的情况下,消息不会从数据库表中删除,并且服务器在重新启动时选择这些消息。如果延迟发生3次

,如何确保从表中删除消息
<int:chain input-channel="delayerChannel"
    output-channel="checkMessageInProgress">
    <int:header-enricher>
    <!-- Exception/ERROR handling for flows originating from Delayer -->
        <int:header name="errorChannel" value="exceptionChannel"
            overwrite="true" />
        <int:header name="retryCount" overwrite="true" type="int"
            expression="headers['retryCount'] == null ? 0 : headers['retryCount'] + 1" />
    </int:header-enricher>
    <!-- If retryCount maxed out -discard message and log it in error table -->
    <int:filter expression="(headers['retryCount'] lt 3)"
        discard-channel="raiseExceptionChannel">
    </int:filter>
    <!-- Configurable delay - fetch from property file -->
    <int:delayer id="Delayer" default-delay="${timeout}"
        message-store="mymessageStore">
        <!-- Transaction management for flows originating from the Delayer -->
        <int:transactional transactionmanager="myAppTransactionManager"/>
    </int:delayer>
</int:chain>

1 个答案:

答案 0 :(得分:1)

这并不奇怪。由于您使用事务资源(数据库),因此任何下游异常都会导致事务回滚,因此不会删除数据。

在抛出异常之前,请考虑将消息转移到单独的线程。这样交易就会被提交。