spring batch 1:簡介

最近因項目需要開始使用spring batch作爲批處理方案,結合Quartz開發定時批處理任務。此次的模塊開發中使用了spring、mybatis。
另外需要說明:官方文檔中是結合spring boot使用,如果項目中使用了spring boot的同學不需要像本文中一樣還是使用xml配置定義job、step等。
一、spring batch
spring batch:建立在Spring框架的基礎之上,它遵循Spring的慣例.spring batch包括日誌/跟蹤,事務管理,作業處理統計,作業重新啓動,跳過和資源管理。
二、spring batch 適用環境
    1. 比如商城的提貨通知,當某一批次物流到達後需要通知用戶提貨。
    2. 繳費扣款、續訂等業務:當前業務觸發則進行查詢、讀取適用信息,再根據業務邏輯進行扣款、或者通知業務,完成後批量寫入庫。
    3. 優惠券等:優惠券到期、發放等。
    4. 等等等等。
三、spring batch 基本組成:Job、setp、ItemReader、ItemProcessor、ItemWriter、Partitioner
     1. org.springframework.batch.core.Job:batch Job,同時也是執行Job的入口;
     2. org.springframework.batch.core.Step:job中的step,提供了執行Step的能力;
     3. org.springframework.batch.item.ItemReader<T>:讀數據(包括文件、數據庫等)提供了讀取數據的能力;
     4. org.springframework.batch.item.ItemProcessor<T>:業務處理(自定義業務)我們可以通過它應用業務邏輯到每一條要處理的數據;
     5. org.springframework.batch.item.ItemWriter<T>:寫數據(包括文件、數據庫等)提供了寫數據的能力;
     6. org.springframework.batch.core.partition.support.Partitioner:參數處理、傳遞,包括任務中傳遞的參數,根據需求傳遞的參數等


附錄
1. [ IBM developerworks 詳細介紹了spring batch的使用 ](http://www.ibm.com/developerworks/cn/java/j-lo-springbatch1/)
2. [spring.io](http://projects.spring.io/spring-batch/#quick-start)
3. [Spring Batch中文文檔](https://kimmking.gitbooks.io/springbatchreference/content/01_introduction/11.html)

如有疑問請加公衆號(K171),如果覺得對您有幫助請 github start
公衆號_k171

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章