Announcement Announcement Module
Collapse
No announcement yet.
Exception rethrowing to Spring Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception rethrowing to Spring Integration

    Hi,

    I'm having a case scenario in which I use Spring Integration (which is amazing) that is getting messagese form RabbitMQ and creating Spring Batch (also amazing) jobs on the fly. When everything goes according to plan, it's all good, however my problem is when an exception is thrown in a batch tasklet.

    In order to process errors, the ideal would be to let SI see and exception and it does not seam to.
    I tried to put in a JobExecutionListener

    Code:
    @Override
    	public void afterJob(JobExecution jobExecution) {
    
    		if (!jobExecution.getAllFailureExceptions().isEmpty()) {
    			ExitStatus exitStatus = ExitStatus.FAILED;
    			for (Throwable e : jobExecution.getAllFailureExceptions()) {
    				exitStatus = exitStatus.addExitDescription(e);
    			}
    			jobExecution.setExitStatus(exitStatus);
    			
    			throw new RuntimeException("Execution " + jobExecution.getId() + " failed");
    		}
    	}
    And rethrow the exception but it is still moved to the error massege. Is is possible to get both, log the exception in the repository database as a an exit status and throw an exception to SI to enable error channel processing?

    Cheers,
    Piotr

  • #2
    Ok, figured it out for myself. Basically I added another service-activator in the chain that is failing (or the last chain/service). As SB returns a JobExecution with all the interesting stuff in it, I can check the exit status and if its "FAILED" can throw an exception.

    cheers,
    pejot

    Comment

    Working...
    X