2017-07-05 29 views
0

什么是标准配置,用于确保从站上的例外映射到主站上的响应,这表明远程步骤实际上失败了?弹簧批量集成 - 远程分块从站例外

目前在从属服务激活器中发生的任何异常都会完全停止流程,并且在主服务器超时之前我无法对主服务器做出响应。我可以在从站上添加一些重试(使用手册中的this信息),但是如果它完全失败或者是一个异常,我不想重试,我需要立即向主站发送失败响应。

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

回答

1

通过分区,您应该得到一个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

+0

这对分区;我添加了关于分块的评论。 –

+0

好的。我配置了一个'FaultTolerantChunkProcessor'而不是'SimpleChunkProcessor'(在我下降到1的块大小之前)并且在'ChunkProcessorChunkHandler.process'中处理这个似乎导致异常不传播。我觉得我现在很好。谢谢您的帮助。 –