How to set up fault tolerance programmatically for spring tasklet (not fragment)

The software fault tolerance setting for a piece works as follows:

stepBuilders.get("step")
  .<Partner,Partner>chunk(1)
  .reader(reader())
  .processor(processor())
  .writer(writer())
  .listener(logProcessListener())
  .faultTolerant()
  .skipLimit(10)
  .skip(UnknownGenderException.class)
  .listener(logSkipListener())
  .build();

The trick is that with the addition of "chunk", the chain switches to SimpleStepBuilder, which offers a "faultTolerant" method.

My question is how to do this if you just have a mascot (no reader, processor, writer)?

The task definition works as follows:

stepBuilders.get("step")
  .tasklet(tasklet())
  .build();

Using the "tasklet" switches to TaskletStepBuilder, which does not offer the "faultTolerant" method. Therefore, I see no way to define properties such as skipLimit, etc.

Any ideas?

+4
source share
2

A Tasklet "" , - . Spring Retry in the raw (1.1.0.RELEASE , , @Retryable ).

+2

, @DaveSyer org.springframework.retry: spring -retry: 1.1.0.RELEASE , :

Tasklet tasklet = // whatever
ProxyFactory proxyFactory = new ProxyFactory(Tasklet, new SingletonTargetSource(tasklet));
proxyFactory.addAdvice(RetryInterceptorBuilder.stateless()
                                              .maxAttempts(3)
                                              .build());
Step step = stepBuilderFactory.get("taskName")
                              .tasklet((Tasklet)proxyFactory.proxy)
                              .build();

, , - , maxAttempts. ExceptionHandler , . , , pointcut, .

0

Source: https://habr.com/ru/post/1539612/


All Articles