Spring 批处理集成 -- 远程分块从属异常



确保从站上的异常映射到主站上的响应的标准配置是什么,该响应将指示远程步骤实际上失败了?

目前,从属服务器上的服务激活器中发生的任何异常都会完全停止流,在整个事情超时之前,我在主服务器上没有得到任何响应。 我可以在从站上添加几次重试(使用手册中的此信息),但如果它完全失败或是一个例外,我不想重试,我需要立即将失败响应发送给主站。

不幸的是,关于远程分块的文档非常稀疏,我找不到任何显示如何处理这个问题的内容。

使用分区,无论成功/失败如何,您都应该获得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)

最新更新