gpt4 book ai didi

java - 如何从 spring Batch 步骤返回自定义 RepeatStatus

转载 作者:行者123 更新时间:2023-11-30 06:26:27 24 4
gpt4 key购买 nike

步骤类:GenerateReferenceNumber

package com.npst.imps.action;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import com.npst.imps.utils.TransactionResponseData;
public class GenerateReferenceNumber implements Tasklet {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
double rrn= Math.random();
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("rrn", rrn);
double tid= (double) chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().get("tid");
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("trnsactionstatus", "RRN generated for Tid::"+tid+" is "+rrn);
TransactionResponseData transactionResponseData =(TransactionResponseData) chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().get("transactionResponseData");
transactionResponseData.setRrn(rrn+"");
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("transactionResponseData", transactionResponseData);

return RepeatStatus.FINISHED;
}

}

我如何返回我自己定义的状态,而不是 Repeatstatus.FINISHED ,并根据它们决定下一步。自定义状态,如成功、失败、部分等。

batchjob.xml

<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-3.0.xsd">
<job id="MBSFT">
<step id="PrepareTid" allow-start-if-complete="true" next="PrepareRRN">
<tasklet ref="PrepareTransactionId" />
</step>

<step id="PrepareRRN" allow-start-if-complete="true">
<tasklet ref="GenerateReferenceNumber" />
<next on="COMPLETED" to="IdentifyImpsService" />
</step>

<step id="IdentifyImpsService" allow-start-if-complete="true">
<tasklet ref="IdentifyIMPSRequestType" />
<next on="COMPLETED" to="FetchNBIN" />
</step>

<step id="FetchNBIN" allow-start-if-complete="true">
<tasklet ref="FetchNBINFromIFSC" />
</step>
</job>
</beans:beans>

最佳答案

我想这是不可能的。
您可以将自定义返回状态放入 StepExecution,使用 ExecutionContextPromotionListener将属性从步骤移动到作业执行上下文,然后使用 JobExecutionDecider重定向流量。

关于java - 如何从 spring Batch 步骤返回自定义 RepeatStatus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47108412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com