【问题标题】:Spring Batch Integration, Email to be sent out in case of JobInstanceAlreadyCompleteExceptionSpring Batch Integration,在 JobInstanceAlreadyCompleteException 的情况下发送电子邮件
【发布时间】:2015-07-16 18:16:45
【问题描述】:

我想在以下代码/配置中的某处放置一个钩子,以便能够发现 JobInstanceAlreadyCompleteException,然后通过电子邮件向生产支持团队发送邮件告知发生了这种情况。

我在 Spring Batch 中尝试了 JobExecutionListener#beforeJob() 方法,但 JobInstanceAlreadyCompleteException 在作业执行之前发生。

我正在使用文档中的这个 Spring Batch Integration 配置:

<int:channel id="inboundFileChannel"/>
<int:channel id="outboundJobRequestChannel"/>
<int:channel id="jobLaunchReplyChannel"/>

<int-file:inbound-channel-adapter id="filePoller"
    channel="inboundFileChannel"
    directory="file:/tmp/myfiles/"
    filename-pattern="*.csv">
<int:poller fixed-rate="1000"/>

</int-file:inbound-channel-adapter>

<int:transformer input-channel="inboundFileChannel"
    output-channel="outboundJobRequestChannel">
    <bean class="io.spring.sbi.FileMessageToJobRequest">
       <property name="job" ref="personJob"/>
       <property name="fileParameterName" value="input.file.name"/>
    </bean>
</int:transformer>

我想处理JobInstanceAlreadyCompleteException,以防相同的 CSV 文件名作为作业参数出现。我要扩展org.springframework.integration.handler.LoggingHandler 吗?

我注意到该类正在报告错误:

ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={input.file.name=C:\Users\csv\file2015.csv}.  If you want to run this job again, change the parameters.

【问题讨论】:

    标签: spring-batch spring-integration


    【解决方案1】:

    ERROR org.springframework.integration.handler.LoggingHandler 是从您的&lt;int-file:inbound-channel-adapter&gt; 上的&lt;poller&gt; 到达的默认errorChannel 完成的。

    因此,要手动处理,您只需指定自己的error-channel 即可继续发送电子邮件:

    <int-file:inbound-channel-adapter>
        <int:poller fixed-rate="1000" error-channel="sendErrorToEmailChannel"/>
    </int-file:inbound-channel-adapter>
    
    <int-mail:outbound-channel-adapter id="sendErrorToEmailChannel"/>
    

    当然,在通过电子邮件发送 ti 之前,您必须进行一些ErrorMessage 转换,但这已经是目标业务逻辑实现的细节。

    【讨论】:

      猜你喜欢
      • 2014-01-01
      • 1970-01-01
      • 2011-06-06
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 2021-05-19
      相关资源
      最近更新 更多