确保从站上的异常映射到主站上的响应(指示远程步骤实际上失败)的标准配置是什么?
目前,从站上的服务激活器中发生的任何异常都会完全停止流程,并且在整个过程超时之前我在主站上没有得到任何响应。我可以在从站上添加几次重试(使用手册中的 this 信息),但如果它完全失败或者是一个异常(exception),我不想重试,我需要立即将失败响应发送到主站。
不幸的是,有关远程分块的文档非常稀疏,我找不到任何显示如何处理此问题的内容。
最佳答案
通过分区,无论成功/失败,您都应该返回 StepExecution
:
@ServiceActivator
public StepExecution handle(StepExecutionRequest request) {
Long jobExecutionId = request.getJobExecutionId();
Long stepExecutionId = request.getStepExecutionId();
StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
if (stepExecution == null) {
throw new NoSuchStepException("No StepExecution could be located for this request: " + request);
}
String stepName = request.getStepName();
Step step = stepLocator.getStep(stepName);
if (step == null) {
throw new NoSuchStepException(String.format("No Step with name [%s] could be located.", stepName));
}
try {
step.execute(stepExecution);
}
catch (JobInterruptedException e) {
stepExecution.setStatus(BatchStatus.STOPPED);
// The receiver should update the stepExecution in repository
}
catch (Throwable e) {
stepExecution.addFailureException(e);
stepExecution.setStatus(BatchStatus.FAILED);
// The receiver should update the stepExecution in repository
}
return stepExecution;
}
(StepExecutionRequestHandler
)。
通过分块,您应该以任何方式获得 ChunkResponse
...
@ServiceActivator
public ChunkResponse handleChunk(ChunkRequest<S> chunkRequest) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Handling chunk: " + chunkRequest);
}
StepContribution stepContribution = chunkRequest.getStepContribution();
Throwable failure = process(chunkRequest, stepContribution);
if (failure != null) {
logger.debug("Failed chunk", failure);
return new ChunkResponse(false, chunkRequest.getSequence(), chunkRequest.getJobId(), stepContribution, failure.getClass().getName()
+ ": " + failure.getMessage());
}
if (logger.isDebugEnabled()) {
logger.debug("Completed chunk handling with " + stepContribution);
}
return new ChunkResponse(true, chunkRequest.getSequence(), chunkRequest.getJobId(), stepContribution);
}
(ChunkProcessorChunkHandler
)
关于java - Spring Batch 集成——远程分块从属异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44933331/