SlideShare a Scribd company logo
SpringBatch: une solution quasi-complète du batch processing en JEE   Hamdi Makni CCJ Arrow TechDays-Sep-2009
Road map Exemple de batch sans SpringBatch Problématique C’est quoi spring batch? Exemple de batch avec SpringBatch Architecture Notions de base Features Best pratices références
Exemple sans SpringBatch public   void  proceedBatch() { FileCreator fileCreator =  null ; try  { PropertyPlaceholderConfigurer cfg =  new  PropertyPlaceholderConfigurer(); cfg.setLocation( new  ClassPathResource("integration.properties")); cfg.postProcessBeanFactory(_beanFactory); jdbcBatchDao = (JdbcDaoBatchSupport) _beanFactory.getBean(getDaoBeanName()); fileCreator =  new  FileCreator("flatworm/INGMovementFlatWorm.xml", "INGMOVEMENT"+  new  Date().getTime()); fileCreator.open(); fileCreator.setRecordSeperator("\n"); List records = jdbcBatchDao.findRecords(); if  (records !=  null ) { for  (Iterator iterator = records.iterator(); iterator.hasNext();) { INGMovement movement = (INGMovement) iterator.next(); fileCreator.setBean("INGMovement", movement); fileCreator.write("INGMovementRecord"); } }  else  { log.warn("No Data Found on DB to extract"); } fileCreator.close(); }  catch  (IOException e) { log.error(e.getMessage()); e.printStackTrace(); System. exit (0); } System. exit (0); }
Exemple sans SpringBatch (DEMO)
Problématiques à résoudre Traitement par lot Performance Reprise d’erreurs Skip errors Gestion de transactions (ou pas?) Scénarios classiques: file<->file file<->db
SpringBatch Framework de batch processing en java Répond aux besoins récurrents et classiques du traitement de données par lot Fait partie de SpringPortfolio, donc basé sur Spring framework Implémentation DDD (Domain Driven Design) Solution quasi-complète Écrit par SpringSource + Accenture
Exemple avec SpringBatch (DEMO)
Architecture Application : business spécifique, implémentations développeur Core : coeur de spring batch, job, step, jobrepository, joblauncher… Infrastructure : implémentations de base de ItemReader, ItemWriter,…
Notions de base SpringBatch
JobRepository Référentiel (ou dépôt) de SpringBatch Deux implémentations: <batch:job-repository id= &quot;jobRepositoryMap&quot; /> <batch:job-repository id= &quot;jobRepository&quot;  data-source= &quot;dataSource&quot;  transaction-manager= &quot;transactionManager&quot;  table-prefix= &quot;BATCH_&quot;  isolation-level-for-create= &quot;SERIALIZABLE&quot;   />
JobLauncher <bean id= &quot;jobLauncher&quot;  class= &quot;org.springframework.batch.core.launch.support.SimpleJobLauncher&quot; > <property  name= &quot;jobRepository&quot;  ref= &quot;jobRepository&quot;  /> </bean>
Job/step/tasklet/chunk Un job est une suite d’étape, séquentielles, parallèles, synchrones, asynchrones … Une étape est un task, une tache, à exécuter Un task est une simple commande, ou bien une itération de traitements sur des lots de données (ou chunk)
Job <batch:job id= &quot;accountFilterToClientsJob&quot; job-repository= &quot;jobRepository&quot; > <batch:step id= &quot;accountFilterToClientsStep&quot; > <batch:tasklet> <batch:chunk commit-interval= &quot;100&quot; reader= &quot;accountFilterToClientsReader&quot;   writer= &quot;accountFilterToClientsWriter&quot; processor= &quot;accountFilterToClientsProcessor&quot; > </batch:chunk> </batch:tasklet> </batch:step> </batch:job>
Step/task Deux types de step: Simple tasklet: une simple tache à exécuter Chunk (ou item V1) oriented tasklet: traitement élément par élément, ou lot par lot.
Simple tasklet <batch:step id= &quot;initBatchStagingStep&quot; > <batch:tasklet job-repository= &quot;jobRepository&quot; transaction-manager= &quot;jpaTransactionManager&quot;   ref= &quot;initBatchStagingTasklet&quot;  > </batch:tasklet> </batch:step> <bean id= &quot;initBatchStagingTasklet&quot;  class= « coco.batch.springbatch.tasklet.JdbcTasklet&quot; > <property name= &quot;dataSource&quot;  ref= &quot;dataSource&quot;  /> <property name= &quot;sqlRequest&quot;  value= &quot;update batch_staging set job_id = ? &quot;  /> </bean>
Chunk oriented tasklet
ItemReader Deux principaux types de reader: file reader, ou DB reader Exemple de itemReader: FlatFileItemReader   JdbcCursorItemReader   JmsItemReader   JpaPagingItemReader   ItemReaderAdapter
Flat File Item Reader <bean id= &quot;accountFilterToClientsReader&quot;  class= &quot;org.springframework.batch.item.file.FlatFileItemReader&quot; > <property name= &quot;resource&quot; > <bean class= &quot;org.springframework.core.io.FileSystemResource&quot; > <constructor-arg type= &quot;java.lang.String«  value= &quot;${file.thaler.accountsfilter.in}&quot;  /> </bean> </property> <property name= &quot;lineMapper&quot; > <bean class= &quot;org.springframework.batch.item.file.mapping.DefaultLineMapper&quot; > <property name= &quot;lineTokenizer&quot; > <bean class= &quot;org.springframework.batch.item.file.transform.DelimitedLineTokenizer&quot; > <property name= &quot;delimiter&quot;  value= &quot;;&quot;  /> <property name= &quot;names&quot;  value= &quot;accNumber,accType&quot; ></property> </bean> </property> <property name= &quot;fieldSetMapper&quot; > <bean class= &quot;org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper&quot; > <property name= &quot;prototypeBeanName&quot;  value= &quot;accountsFilter&quot; /> </bean> </property> </bean> </property> </bean>
DataBase Reader <bean id= &quot;spFundAccountItemReader&quot; class= &quot;org.springframework.batch.item.database.JdbcCursorItemReader&quot; > <property name= &quot;dataSource&quot;  ref= &quot;${dataSource}&quot;  /> <property name= &quot;sql&quot;  value= &quot; select cl1 from tab2&quot; /> <property name= &quot;rowMapper&quot; > <bean class= &quot;coco.project.MyRowMapper&quot; /> </property> </bean>
ItemWriter Comme pour les reader, les 2 types de writer les plus utilisés sont les File Writer et les DB Writer. Exemples d’implémentation de Writer: FlatFileItemWriter   JdbcBatchItemWriter   ItemWriterAdapter   CompositeItemWriter   JmsItemWriter   HibernateItemWriter
Flat File Item Writer <bean id= &quot;contratBaseItemWriter&quot;  class= &quot;org.springframework.batch.item.file.FlatFileItemWriter&quot; > <property name= &quot;headerCallback&quot;  ref= &quot;contratBaseHeaderCallback&quot;  /> <property name= &quot;footerCallback&quot;  ref= &quot;contratBaseFooterCallback&quot;  /> <property name= &quot;resource&quot;  ref= &quot;contratBaseFileOutputLocator&quot;  /> <property name= &quot;lineAggregator&quot; > <bean class= &quot;org.springframework.batch.item.file.transform.DelimitedLineAggregator&quot; > <property name= &quot;delimiter&quot;  value= &quot;;&quot;  /> <property name= &quot;fieldExtractor&quot; > <bean  class= &quot;org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor&quot; > <property name= &quot;names&quot;  value= &quot;recordType,name1,name2&quot;  /> </bean> </property> </bean> </property> </bean>
Data Base Writer <bean id= &quot;accountFilterToClientsWriter&quot; class= &quot;org.springframework.batch.item.database.JdbcBatchItemWriter&quot; > <property name= &quot;dataSource&quot;  ref= &quot;dataSource&quot;  /> <property name= &quot;sql&quot; value= &quot;insert into cl_accounts_filter (ACC_NUMBER, ACC_TYPE, B2B , MAJ_DT_DATECRE, MAJ_DT_DATEMAJ)  values (:accNumber, :accType, :b2b, :majDtDateCre,  :majDtDatemaj)&quot;  /> <property name= &quot;itemSqlParameterSourceProvider&quot; > <bean class= &quot;org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider&quot;  /> </property> </bean>
Item Writer Adapter Délègue l’écriture à un service business: réutiliser un bean business <bean id= &quot;ingClientItemWriter&quot; class= &quot;org.springframework.batch.item.adapter.ItemWriterAdapter&quot; > <property name= &quot;targetObject&quot;  ref=  &quot; simpleService&quot;  /> <property name= &quot; targetMethod &quot;  value= &quot;saveObject&quot;  /> </bean>
Features: skip, rollback, no-rollback, restart <batch:step id= &quot;stagingObjectClientStep&quot;  > <batch:tasklet job-repository= &quot;jobRepository&quot;  transaction-manager= &quot;jpaTransactionManager&quot; > <batch:chunk  reader= &quot;clientStagingFileItemReader&quot; writer= &quot;stagingObjectClientWriter&quot; commit-interval= &quot;100&quot; skip-limit = &quot;100000&quot; task-executor= &quot;taskExecutor&quot; retry-limit = &quot;2&quot; > <batch: skippable-exception-classes > coco .exception.BusinessException </batch: skippable-exception-classes > <batch: fatal-exception-classes > coco .exception.FatalException </batch: fatal-exception-classes > <batch: retryable-exception-classes > coco .exception.NetworkException </batch: retryable-exception-classes > </batch:chunk> <batch: no-rollback-exception-classes > coco .exception.ValidationException </batch: no-rollback-exception-classes > </batch:tasklet> </batch:step>
Traitement conditionnel Contrôler le passage d’une étape à une autre Le passage d’une étape à une autre dépend du résultat de l’étape courante <job id=&quot;job&quot;> <step id=&quot;stepA&quot; parent=&quot;s1&quot;> <next on=&quot;*&quot; to=&quot;stepB&quot; /> <next on=&quot;FAILED&quot; to=&quot;stepC&quot; /> </step> <step id=&quot;stepB&quot; parent=&quot;s2&quot; next=&quot;stepC&quot; /> <step id=&quot;stepC&quot; parent=&quot;s3&quot; /> </job>
Features: multithreading Il suffit de mettre un TaskExecutor dans son Step pour que tout se lance en multithread Remarque: tout n’est pas en thread safe dans springBatch. Il faut développer ses propres reader et services synchronisés
Features: multithreading <bean id=&quot;taskExecutor&quot; class=&quot;org.springframework.core.task.SimpleAsyncTaskExecutor&quot; /> <batch:step id=&quot;stagingObjectClientStep&quot; > <batch:tasklet job-repository=&quot;jobRepository&quot; transaction-manager=&quot;jpaTransactionManager&quot;> <batch:chunk reader=&quot;ingClientStagingFileItemReader&quot; writer=&quot;stagingObjectClientWriter&quot; task-executor=&quot; taskExecutor &quot; > </batch:chunk> </batch:tasklet> </batch:step>
Features: Parallel step L’une des nouvelles fonctionnalités très utiles de SpringBatch2 Permet de lancer plusieurs étapes en même temps, et non en séquentiel. Une nouvelle notion de Flow
Features: Parallel step <batch:job id= &quot;migrationCCIngToClientsJob&quot;  parent= &quot;simpleJob&quot; > <batch:step id= &quot;cleanBatchStagingStep_&quot;  parent= &quot;cleanBatchStagingStep&quot;  next= &quot;stagingFileStep&quot;  /> <batch:split task-executor= &quot;taskExecutor&quot;  id= &quot;stagingFileStep&quot;  next= &quot;headerFooterClientStep_&quot; > <batch:flow> <batch:step id= &quot;stagingFileClientStep_&quot;  parent= &quot;stagingFileClientStep&quot; /> </batch:flow> <batch:flow> <batch:step id= &quot;stagingFileContractStep_&quot;  parent= &quot;stagingFileContractStep&quot;  /> </batch:flow> <batch:flow> <batch:step id= &quot;stagingFileRelationStep_&quot;  parent= &quot;stagingFileRelationStep&quot;  /> </batch:flow> </batch:split> </batch:job>
Remote processing Utilisé si la partie traitement est plus coûteuse que la lecture Permet de traiter les éléments sur plusieurs process distant Utilisation de JMS, de solutions de grid computing, de partage de mémoire
Features: Partitionning Partitionner les données et les traiter sur plusieurs étapes en parallèle
Best pratices Paging Staging file Lecture moins coûteuse que le traitement Parallel processing Éviter les caches à longues durée de vie Splitter les gros fichiers
Références http://static.springsource.org/spring-batch/reference/html-single/index.html http://www.cafebabe.me/2008/05/spring-batch-hello-world-1.html http:// static.springsource.org / spring-batch / http://blog.octo.com/spring-batch-par-quel-bout-le-prendre/

More Related Content

Viewers also liked (20)

PPTX
Persistence in the cloud with bosh
m_richardson
 
PPTX
Developing highly scalable applications with Symfony and RabbitMQ
Alexey Petrov
 
PPTX
Fostering a Culture of Analytics
Alex Welch
 
PPTX
e-Extortion Trends and Defense
Erik Iker
 
PPTX
Reversing malware analysis training part2 introduction to windows internals
Cysinfo Cyber Security Community
 
PDF
Gartner 2017 London: How to re-invent your IT Architecture?
LeanIX GmbH
 
PDF
Astricon 2016 - Scaling ARI and Production
Dan Jenkins
 
PPT
Docker introduction
Phuc Nguyen
 
PDF
AWS + Puppet = Dynamic Scale
Shiva Narayanaswamy
 
PPT
Introduction to smpc
Cysinfo Cyber Security Community
 
PPTX
Interesting Places in Poland
wojcik_agnieszka
 
PPTX
Reversing malware analysis training part3 windows pefile formatbasics
Cysinfo Cyber Security Community
 
PPTX
Security For Humans
conjur_inc
 
PPTX
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Bhakti Mehta
 
PPT
Een Gezond Gebit2
guest031320
 
PDF
Evolution of OPNFV CI System: What already exists and what can be introduced
OPNFV
 
PDF
Neuigkeiten von DEPAROM & Co
Arne Krueger
 
PPTX
You know, for search
Peter van der Weerd
 
PPTX
Risk management
hussnain ali
 
Persistence in the cloud with bosh
m_richardson
 
Developing highly scalable applications with Symfony and RabbitMQ
Alexey Petrov
 
Fostering a Culture of Analytics
Alex Welch
 
e-Extortion Trends and Defense
Erik Iker
 
Reversing malware analysis training part2 introduction to windows internals
Cysinfo Cyber Security Community
 
Gartner 2017 London: How to re-invent your IT Architecture?
LeanIX GmbH
 
Astricon 2016 - Scaling ARI and Production
Dan Jenkins
 
Docker introduction
Phuc Nguyen
 
AWS + Puppet = Dynamic Scale
Shiva Narayanaswamy
 
Introduction to smpc
Cysinfo Cyber Security Community
 
Interesting Places in Poland
wojcik_agnieszka
 
Reversing malware analysis training part3 windows pefile formatbasics
Cysinfo Cyber Security Community
 
Security For Humans
conjur_inc
 
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Bhakti Mehta
 
Een Gezond Gebit2
guest031320
 
Evolution of OPNFV CI System: What already exists and what can be introduced
OPNFV
 
Neuigkeiten von DEPAROM & Co
Arne Krueger
 
You know, for search
Peter van der Weerd
 
Risk management
hussnain ali
 

Spring Batch

  • 1. SpringBatch: une solution quasi-complète du batch processing en JEE Hamdi Makni CCJ Arrow TechDays-Sep-2009
  • 2. Road map Exemple de batch sans SpringBatch Problématique C’est quoi spring batch? Exemple de batch avec SpringBatch Architecture Notions de base Features Best pratices références
  • 3. Exemple sans SpringBatch public void proceedBatch() { FileCreator fileCreator = null ; try { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation( new ClassPathResource(&quot;integration.properties&quot;)); cfg.postProcessBeanFactory(_beanFactory); jdbcBatchDao = (JdbcDaoBatchSupport) _beanFactory.getBean(getDaoBeanName()); fileCreator = new FileCreator(&quot;flatworm/INGMovementFlatWorm.xml&quot;, &quot;INGMOVEMENT&quot;+ new Date().getTime()); fileCreator.open(); fileCreator.setRecordSeperator(&quot;\n&quot;); List records = jdbcBatchDao.findRecords(); if (records != null ) { for (Iterator iterator = records.iterator(); iterator.hasNext();) { INGMovement movement = (INGMovement) iterator.next(); fileCreator.setBean(&quot;INGMovement&quot;, movement); fileCreator.write(&quot;INGMovementRecord&quot;); } } else { log.warn(&quot;No Data Found on DB to extract&quot;); } fileCreator.close(); } catch (IOException e) { log.error(e.getMessage()); e.printStackTrace(); System. exit (0); } System. exit (0); }
  • 5. Problématiques à résoudre Traitement par lot Performance Reprise d’erreurs Skip errors Gestion de transactions (ou pas?) Scénarios classiques: file<->file file<->db
  • 6. SpringBatch Framework de batch processing en java Répond aux besoins récurrents et classiques du traitement de données par lot Fait partie de SpringPortfolio, donc basé sur Spring framework Implémentation DDD (Domain Driven Design) Solution quasi-complète Écrit par SpringSource + Accenture
  • 8. Architecture Application : business spécifique, implémentations développeur Core : coeur de spring batch, job, step, jobrepository, joblauncher… Infrastructure : implémentations de base de ItemReader, ItemWriter,…
  • 9. Notions de base SpringBatch
  • 10. JobRepository Référentiel (ou dépôt) de SpringBatch Deux implémentations: <batch:job-repository id= &quot;jobRepositoryMap&quot; /> <batch:job-repository id= &quot;jobRepository&quot; data-source= &quot;dataSource&quot; transaction-manager= &quot;transactionManager&quot; table-prefix= &quot;BATCH_&quot; isolation-level-for-create= &quot;SERIALIZABLE&quot; />
  • 11. JobLauncher <bean id= &quot;jobLauncher&quot; class= &quot;org.springframework.batch.core.launch.support.SimpleJobLauncher&quot; > <property name= &quot;jobRepository&quot; ref= &quot;jobRepository&quot; /> </bean>
  • 12. Job/step/tasklet/chunk Un job est une suite d’étape, séquentielles, parallèles, synchrones, asynchrones … Une étape est un task, une tache, à exécuter Un task est une simple commande, ou bien une itération de traitements sur des lots de données (ou chunk)
  • 13. Job <batch:job id= &quot;accountFilterToClientsJob&quot; job-repository= &quot;jobRepository&quot; > <batch:step id= &quot;accountFilterToClientsStep&quot; > <batch:tasklet> <batch:chunk commit-interval= &quot;100&quot; reader= &quot;accountFilterToClientsReader&quot; writer= &quot;accountFilterToClientsWriter&quot; processor= &quot;accountFilterToClientsProcessor&quot; > </batch:chunk> </batch:tasklet> </batch:step> </batch:job>
  • 14. Step/task Deux types de step: Simple tasklet: une simple tache à exécuter Chunk (ou item V1) oriented tasklet: traitement élément par élément, ou lot par lot.
  • 15. Simple tasklet <batch:step id= &quot;initBatchStagingStep&quot; > <batch:tasklet job-repository= &quot;jobRepository&quot; transaction-manager= &quot;jpaTransactionManager&quot; ref= &quot;initBatchStagingTasklet&quot; > </batch:tasklet> </batch:step> <bean id= &quot;initBatchStagingTasklet&quot; class= « coco.batch.springbatch.tasklet.JdbcTasklet&quot; > <property name= &quot;dataSource&quot; ref= &quot;dataSource&quot; /> <property name= &quot;sqlRequest&quot; value= &quot;update batch_staging set job_id = ? &quot; /> </bean>
  • 17. ItemReader Deux principaux types de reader: file reader, ou DB reader Exemple de itemReader: FlatFileItemReader JdbcCursorItemReader JmsItemReader JpaPagingItemReader ItemReaderAdapter
  • 18. Flat File Item Reader <bean id= &quot;accountFilterToClientsReader&quot; class= &quot;org.springframework.batch.item.file.FlatFileItemReader&quot; > <property name= &quot;resource&quot; > <bean class= &quot;org.springframework.core.io.FileSystemResource&quot; > <constructor-arg type= &quot;java.lang.String« value= &quot;${file.thaler.accountsfilter.in}&quot; /> </bean> </property> <property name= &quot;lineMapper&quot; > <bean class= &quot;org.springframework.batch.item.file.mapping.DefaultLineMapper&quot; > <property name= &quot;lineTokenizer&quot; > <bean class= &quot;org.springframework.batch.item.file.transform.DelimitedLineTokenizer&quot; > <property name= &quot;delimiter&quot; value= &quot;;&quot; /> <property name= &quot;names&quot; value= &quot;accNumber,accType&quot; ></property> </bean> </property> <property name= &quot;fieldSetMapper&quot; > <bean class= &quot;org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper&quot; > <property name= &quot;prototypeBeanName&quot; value= &quot;accountsFilter&quot; /> </bean> </property> </bean> </property> </bean>
  • 19. DataBase Reader <bean id= &quot;spFundAccountItemReader&quot; class= &quot;org.springframework.batch.item.database.JdbcCursorItemReader&quot; > <property name= &quot;dataSource&quot; ref= &quot;${dataSource}&quot; /> <property name= &quot;sql&quot; value= &quot; select cl1 from tab2&quot; /> <property name= &quot;rowMapper&quot; > <bean class= &quot;coco.project.MyRowMapper&quot; /> </property> </bean>
  • 20. ItemWriter Comme pour les reader, les 2 types de writer les plus utilisés sont les File Writer et les DB Writer. Exemples d’implémentation de Writer: FlatFileItemWriter JdbcBatchItemWriter ItemWriterAdapter CompositeItemWriter JmsItemWriter HibernateItemWriter
  • 21. Flat File Item Writer <bean id= &quot;contratBaseItemWriter&quot; class= &quot;org.springframework.batch.item.file.FlatFileItemWriter&quot; > <property name= &quot;headerCallback&quot; ref= &quot;contratBaseHeaderCallback&quot; /> <property name= &quot;footerCallback&quot; ref= &quot;contratBaseFooterCallback&quot; /> <property name= &quot;resource&quot; ref= &quot;contratBaseFileOutputLocator&quot; /> <property name= &quot;lineAggregator&quot; > <bean class= &quot;org.springframework.batch.item.file.transform.DelimitedLineAggregator&quot; > <property name= &quot;delimiter&quot; value= &quot;;&quot; /> <property name= &quot;fieldExtractor&quot; > <bean class= &quot;org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor&quot; > <property name= &quot;names&quot; value= &quot;recordType,name1,name2&quot; /> </bean> </property> </bean> </property> </bean>
  • 22. Data Base Writer <bean id= &quot;accountFilterToClientsWriter&quot; class= &quot;org.springframework.batch.item.database.JdbcBatchItemWriter&quot; > <property name= &quot;dataSource&quot; ref= &quot;dataSource&quot; /> <property name= &quot;sql&quot; value= &quot;insert into cl_accounts_filter (ACC_NUMBER, ACC_TYPE, B2B , MAJ_DT_DATECRE, MAJ_DT_DATEMAJ) values (:accNumber, :accType, :b2b, :majDtDateCre, :majDtDatemaj)&quot; /> <property name= &quot;itemSqlParameterSourceProvider&quot; > <bean class= &quot;org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider&quot; /> </property> </bean>
  • 23. Item Writer Adapter Délègue l’écriture à un service business: réutiliser un bean business <bean id= &quot;ingClientItemWriter&quot; class= &quot;org.springframework.batch.item.adapter.ItemWriterAdapter&quot; > <property name= &quot;targetObject&quot; ref= &quot; simpleService&quot; /> <property name= &quot; targetMethod &quot; value= &quot;saveObject&quot; /> </bean>
  • 24. Features: skip, rollback, no-rollback, restart <batch:step id= &quot;stagingObjectClientStep&quot; > <batch:tasklet job-repository= &quot;jobRepository&quot; transaction-manager= &quot;jpaTransactionManager&quot; > <batch:chunk reader= &quot;clientStagingFileItemReader&quot; writer= &quot;stagingObjectClientWriter&quot; commit-interval= &quot;100&quot; skip-limit = &quot;100000&quot; task-executor= &quot;taskExecutor&quot; retry-limit = &quot;2&quot; > <batch: skippable-exception-classes > coco .exception.BusinessException </batch: skippable-exception-classes > <batch: fatal-exception-classes > coco .exception.FatalException </batch: fatal-exception-classes > <batch: retryable-exception-classes > coco .exception.NetworkException </batch: retryable-exception-classes > </batch:chunk> <batch: no-rollback-exception-classes > coco .exception.ValidationException </batch: no-rollback-exception-classes > </batch:tasklet> </batch:step>
  • 25. Traitement conditionnel Contrôler le passage d’une étape à une autre Le passage d’une étape à une autre dépend du résultat de l’étape courante <job id=&quot;job&quot;> <step id=&quot;stepA&quot; parent=&quot;s1&quot;> <next on=&quot;*&quot; to=&quot;stepB&quot; /> <next on=&quot;FAILED&quot; to=&quot;stepC&quot; /> </step> <step id=&quot;stepB&quot; parent=&quot;s2&quot; next=&quot;stepC&quot; /> <step id=&quot;stepC&quot; parent=&quot;s3&quot; /> </job>
  • 26. Features: multithreading Il suffit de mettre un TaskExecutor dans son Step pour que tout se lance en multithread Remarque: tout n’est pas en thread safe dans springBatch. Il faut développer ses propres reader et services synchronisés
  • 27. Features: multithreading <bean id=&quot;taskExecutor&quot; class=&quot;org.springframework.core.task.SimpleAsyncTaskExecutor&quot; /> <batch:step id=&quot;stagingObjectClientStep&quot; > <batch:tasklet job-repository=&quot;jobRepository&quot; transaction-manager=&quot;jpaTransactionManager&quot;> <batch:chunk reader=&quot;ingClientStagingFileItemReader&quot; writer=&quot;stagingObjectClientWriter&quot; task-executor=&quot; taskExecutor &quot; > </batch:chunk> </batch:tasklet> </batch:step>
  • 28. Features: Parallel step L’une des nouvelles fonctionnalités très utiles de SpringBatch2 Permet de lancer plusieurs étapes en même temps, et non en séquentiel. Une nouvelle notion de Flow
  • 29. Features: Parallel step <batch:job id= &quot;migrationCCIngToClientsJob&quot; parent= &quot;simpleJob&quot; > <batch:step id= &quot;cleanBatchStagingStep_&quot; parent= &quot;cleanBatchStagingStep&quot; next= &quot;stagingFileStep&quot; /> <batch:split task-executor= &quot;taskExecutor&quot; id= &quot;stagingFileStep&quot; next= &quot;headerFooterClientStep_&quot; > <batch:flow> <batch:step id= &quot;stagingFileClientStep_&quot; parent= &quot;stagingFileClientStep&quot; /> </batch:flow> <batch:flow> <batch:step id= &quot;stagingFileContractStep_&quot; parent= &quot;stagingFileContractStep&quot; /> </batch:flow> <batch:flow> <batch:step id= &quot;stagingFileRelationStep_&quot; parent= &quot;stagingFileRelationStep&quot; /> </batch:flow> </batch:split> </batch:job>
  • 30. Remote processing Utilisé si la partie traitement est plus coûteuse que la lecture Permet de traiter les éléments sur plusieurs process distant Utilisation de JMS, de solutions de grid computing, de partage de mémoire
  • 31. Features: Partitionning Partitionner les données et les traiter sur plusieurs étapes en parallèle
  • 32. Best pratices Paging Staging file Lecture moins coûteuse que le traitement Parallel processing Éviter les caches à longues durée de vie Splitter les gros fichiers