Steps to learn Spring Batch Service

Spring Batch Service

บริการสปริงแบตช์,,en,บริการแบบชุดช่วยให้การประมวลผลของงานหลายงานเป็นชุดโดยอัตโนมัติ,,en,ฤดูใบไม้ผลิให้โอกาสในการเพิ่มประสิทธิภาพของทรัพยากรและประหยัดค่าใช้จ่ายที่ไม่จำเป็นเพราะบริการชุดฤดูใบไม้ผลิสามารถประมวลผลงานต่าง ๆ ได้อย่างรวดเร็ว,,en,ลองนึกถึงเรื่องนี้ - องค์กรไม่จำเป็นต้องใช้กำลังคนในการปฏิบัติงานซ้ำ ๆ,,en,งานจะทำโดยกรอบโอเพนซอร์ซที่มี API และบริการที่พร้อมทำและยังอนุญาตให้มีการปรับเปลี่ยนการบริการตามความต้องการ,,en,สปริงคืออะไร,,en,องค์กรจำเป็นต้องดำเนินการตามจำนวนการดำเนินธุรกิจเช่นการคำนวณสิ้นเดือน,,en,ใช้เป็นระยะ,,en,กฎเกณฑ์ทางธุรกิจที่ซับซ้อน,,en – How does it work?

ภาพรวม :

The Spring batch services help automate processing of several jobs in batches. It is a framework that provides the APIs and services that can be reused to process one or more jobs in batches. From an enterprise viewpoint, Spring offers an opportunity to optimize its resources and save unnecessary costs because the Spring batch services is able to process several jobs quickly. Think of this – an enterprise does not need to employ manpower to execute repetitive jobs. Instead, the jobs will be done by an open source framework that provides ready made APIs and services and also allows the modification of the services as per requirement.








What is Spring batch?

Enterprises need to process a number of business operations such as month-end calculations, periodically applying complex business rules และการรวมข้อมูลที่ซับซ้อนที่ได้รับจากแหล่งภายนอกประมวลผลซ้ำ ๆ ในชุดข้อมูลขนาดใหญ่จำนวนมากโดยมีการแทรกแซงของมนุษย์น้อยที่สุดหรือไม่มีเลย,,en,Spring Batch ทำสิ่งนั้นอย่างแน่นอน,,en,ชุดฤดูใบไม้ผลิ,,en,ซึ่งเป็นส่วนหนึ่งของ,,en,สปริงผลงาน,,en,เป็นเฟรมเวิร์กโอเพนซอร์สที่ช่วยให้การพัฒนาแอปพลิเคชันการประมวลผลแบทช์,,en,Spring Batch นำเสนอความสามารถในการประมวลผลการดำเนินธุรกิจที่เรียบง่ายและซับซ้อน,,en,ในขณะที่มันมีฟังก์ชั่นที่นำกลับมาใช้ใหม่ที่สามารถประมวลผลบันทึกจำนวนมากรวมถึงการจัดการธุรกรรม,,en,สถิติการประมวลผลงาน,,en,การติดตาม,,en,กระโดด,,en,รีสตาร์ทงานและการจัดการทรัพยากร,,en,นอกจากนี้ยังมีบริการด้านเทคนิคและฟีเจอร์ที่เปิดใช้งานปริมาณมากและงานที่มีประสิทธิภาพสูงผ่านการปรับแต่งและเทคนิคการแบ่งพาร์ติชัน,,en. The Spring Batch does exactly that. The Spring batch, which is a part of the Spring portfolio, is an open source framework that allows the development of batch-processing applications. Spring Batch offers capabilities for processing both simple and complex business operations. While it offers reusable functions that can process large volumes of records including transaction management, job processing statistics, logging/tracing, skip, job restart and resource management, it also offers technical services and features that enable high-volume and high performance batch jobs through optimization and partitioning techniques.

แต่ละส่วนประกอบในสถาปัตยกรรม Spring batch มีบทบาทเฉพาะในการเล่น,,en,ส่วนประกอบของแอปพลิเคชั่นแบทช์เป็นแอพพลิเคชั่นที่ช่วยให้นักพัฒนาซอฟต์แวร์สามารถประมวลผลแบทช์หนึ่งหรือหลายงาน,,en,Spring Batch Core จัดเตรียมสภาพแวดล้อมรันไทม์สำหรับ Batch Application,,en,Spring Batch Infrastructure ให้คลาสที่มีประโยชน์สำหรับการสร้างและเรียกใช้แอพแบบแบตช์,,en,จากมุมมองขององค์กร,,en,เป็นที่พึงปรารถนาที่การดำเนินธุรกิจหรืองานจะเสร็จสมบูรณ์ตามความคาดหวังและภายในเวลาที่กำหนด,,en,องค์กรต้องการดำเนินการให้เสร็จสิ้นให้เร็วที่สุดด้วยการลงทุนทรัพยากรน้อยที่สุดซึ่งอาจเป็นเวลาและบุคลากร,,en,บริการชุดสปริงช่วยให้องค์กรบรรลุวัตถุประสงค์นี้,,en,ข้อได้เปรียบหลักของบริการสปริงแบตช์มีดังต่อไปนี้,,en. The Batch Application component is the application that allows the software developers to batch process one or more jobs. The Spring Batch Core provides the runtime environment for the Batch Application. Lastly, the Spring Batch Infrastructure provides the classes useful for both building and running batch apps.

Must watch – Spring video tutorials

Advantages

From the enterprise viewpoint, it is desirable that business operations or jobs are completed with the expected accuracy and within time. Enterprises want to complete as many operations as quickly possible with the least investment of resources which can be time and personnel. The Spring batch service allows the enterprise to achieve this objective. The main advantages of the Spring batch services are given below.

  • ความพร้อมใช้งานของฟังก์ชั่นที่นำกลับมาใช้ใหม่ได้ซึ่งสามารถทำงานต่างๆเช่นการประมวลผลบันทึกจำนวนมากซึ่งรวมถึงการบันทึก / การติดตาม,,en,และสถิติการประมวลผลงาน,,en,รีสตาร์ทงาน,,en,และการจัดการทรัพยากร,,en,ความพร้อมใช้งานของบริการด้านเทคนิคที่สามารถทำงานที่ซับซ้อนซึ่งเกี่ยวข้องกับงานปริมาณมากและงานที่มีประสิทธิภาพสูง,,en,Spring batch services อาจเป็นทางออกที่ดีที่สุด,,en,เท่าที่เกี่ยวข้องกับการประมวลผลงานแบ็ตช์,,en,การสร้าง Spring Batch Services,,en,ขั้นแรกสร้างโครงการ Java โดยใช้ Maven,,en,mvn archetype,,en,สร้าง -DgroupId = com.techalpine -DartifactId = ExampleSpringBatch,,en,DarchetypeArtifactId = maven-archetype-quickstart -DinteractiveMode = false,,en,ไปที่พรอมต์คำสั่งและแปลงเป็นโครงการ eclipse และนำเข้าใน Eclipse IDE,,en,ทำตามคำสั่งที่แสดงด้านล่าง,,en,ตัวอย่าง cdSpringBatch /,,en,mvn eclipse,,en,คราส,,en, transaction, and job processing statistics, job restart, skip, and resource management.
  • Availability of technical services that can perform complex tasks that involve high-volume and high-performance batch jobs.
  • At the moment, Spring batch services are probably the best available solution, as far as processing of batch jobs are concerned.









Creating Spring Batch Services

First create a Java project using Maven

$ mvn archetype:generate -DgroupId=com.techalpine -DartifactId=ExampleSpringBatch

-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Now, go to command prompt and convert it to eclipse project and import in Eclipse IDE. Follow the commands shown below.

cd ExampleSpringBatch/

$ mvn eclipse:eclipse

ประกาศการพึ่งพาโครงการทั้งหมดใน pom.xml ดังที่แสดงด้านล่าง,,en,กำหนด pom.xml ด้วยการอ้างอิง,,en,maven.apache.org/maven-v4_0_0.xsd,,en,ExampleSpringBatch,,en,ภาพรวม,,en,maven.apache.org,,en,jdk.version,,en,spring.version,,en,spring.batch.version,,en,mysql.driver.version,,en,แกนสปริง,,en,ฤดูใบไม้ผลิ-core,,en,สปริง jdbc,,en,สำหรับฐานข้อมูล,,en,ฤดูใบไม้ผลิ JDBC,,en,Spring Batch dependencies,,en,org.springframework.batch,,en,ฤดูใบไม้ผลิชุดหลัก,,en,ฤดูใบไม้ผลิชุดโครงสร้างพื้นฐาน,,en,โปรแกรมควบคุมฐานข้อมูล MySQL,,en,finalName,,bg,ตัวอย่างเช่นฤดูใบไม้ผลิชุด,,en,org.apache.maven.plugins,,en,Maven-คราสปลั๊กอิน,,en,downloadSources,,en,downloadJavadocs,,en,Maven เรียบเรียงปลั๊กอิน,,en,แหล่ง,,en,การกำหนดงานแบ็ตช์,,en,ส่วนนี้กำหนดลำดับของงานแบ็ตช์,,en,ขั้นตอนดังกล่าวเป็น ‘step1,,en,'ขั้นตอนที่ 2,,en,ภายในไม่กี่ก้าว,,en,แผ่นงานกำหนดหน่วยของงานขนาดเล็กที่จะดำเนินการ,,en,แต่ละกลุ่มแบทช์กำหนดงาน,,en,เราสามารถมีหลายขั้นตอนในงานแบ็ตช์,,en,การอธิบายถึงงานแบตช์และส่วนประกอบ,,en,ชุด =,,en,www.springframework.org/schema/batch,,en,งาน =,,en.

Listing 1: Defining pom.xml with dependencies

<project xmlns=”ที่ http://maven.apache.org/POM/4.0.0″

xmlns:xsi=”ที่ http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=”ที่ http://maven.apache.org/POM/4.0.0

ที่ http://maven.apache.org/maven-v4_0_0.xsd”>

<modelVersion>4.0.0</modelVersion>

<groupId>com.techalpine</groupId>

<artifactId>ExampleSpringBatch</artifactId>

<packaging>jar</packaging>

<version>1.0-SNAPSHOT</version>

<ชื่อ>ExampleSpringBatch</ชื่อ>

<url>ที่ http://maven.apache.org</url>

<properties>

<jdk.version>1.6</jdk.version>

<spring.version>3.2.2.RELEASE</spring.version>

<spring.batch.version>2.2.0.RELEASE</spring.batch.version>

<mysql.driver.version>5.1.25</mysql.driver.version>

</properties>

<dependencies>

<!– Spring Core –>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>${spring.version}</version>

</dependency>

<!– Spring jdbc, for database –>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>${spring.version}</version>

</dependency>

<!– Spring Batch dependencies –>

<dependency>

<groupId>org.springframework.batch</groupId>

<artifactId>spring-batch-core</artifactId>

<version>${spring.batch.version}</version>

</dependency>

<dependency>

<groupId>org.springframework.batch</groupId>

<artifactId>spring-batch-infrastructure</artifactId>

<version>${spring.batch.version}</version>

</dependency>

<!– MySQL database driver –>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>${mysql.driver.version}</version>

</dependency>

</dependencies>

<build>

<finalName>example-spring-batch</finalName>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-eclipse-plugin</artifactId>

<version>2.9</version>

<องค์ประกอบ>

<downloadSources>จริง</downloadSources>

<downloadJavadocs>false</downloadJavadocs>

</องค์ประกอบ>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>2.3.2</version>

<องค์ประกอบ>

<source>${jdk.version}</source>

<target>${jdk.version}</target>

</องค์ประกอบ>

</plugin>

</plugins>

</build>

</project>



Now, defining batch jobs. This section defines sequence of batch jobs. Steps are mentioned as ‘step1′,’step2’ เป็นต้น. Within steps, tasklets define small unit of work to be performed. Each batch chunk defines the work. We can have multiple steps in a batch job.

Listing 2: Describing batch jobs and components

<ถั่ว xmlns =”ที่ http://www.springframework.org/schema/beans”

xmlns:batch=”ที่ http://www.springframework.org/schema/batch”

xmlns:task=”ที่ http://www.springframework.org/schema/task,,en,www.springframework.org/schema/batch/spring-batch-2.2.xsd,,en,samplereport,,en,com.techalpine.spring.batch,,en,ขอบเขต =,,en,แบบเดิม,,en,ชุด,,en,id งาน =,,en,batchJobSample,,en,ขั้นตอน id =,,en,ขั้นตอนที่ 1,,en,tasklet,,en,ตัวอ่านอันจิปาถะ =,,en,ReaderOne,,en,นักเขียน =,,en,WriterOne,,en,หน่วยประมวลผล =,,en,ProcessorOne,,en,กระทำช่วงเวลา =,,en,ก้อน,,en,ขั้นตอนที่ 2,,en,ReaderTwo,,en,WriterTwo,,en,ProcessorTwo,,en,งาน,,en,org.springframework.batch.item.file.FlatFileItemReader,,en,กำลังอ่านไฟล์,,en,CVS / sample.1csv,,en,lineMapper,,en,คลาสถั่ว =,,en,org.springframework.batch.item.file.mapping.DefaultLineMapper,,en,แยกมัน,,en,lineTokenizer,,en,org.springframework.batch.item.file.transform.DelimitedLineTokenizer,,en,การแสดงผล,,en,คลิก,,en,รายได้,,en,fieldSetMapper,,en,org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper,,en,prototypeBeanName,,en,org.springframework.batch.item.xml.StaxEventItemWriter,,en,XML / ผล / sample1.xml,,en,marshaller,,en,ref =,,en,yyy,,en,rootTagName,,ml,CVS / sample2.csv,,en,XML / ผล / sample2.xml,,en,ZZZ,,en,mmm,,en,เราจะเขียนโปรแกรมหลักเพื่อทำงานแบ็ตช์,,en”

xmlns:xsi=”ที่ http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=”ที่ http://www.springframework.org/schema/batch

ที่ http://www.springframework.org/schema/batch/spring-batch-2.2.xsd

ที่ http://www.springframework.org/schema/beans

ที่ http://www.springframework.org/schema/beans/spring-beans-3.2.xsd”>

<ถั่ว id =”samplereport” class =”com.techalpine.spring.batch” scope=”prototype” />

<batch:job id = “batchJobSample”>

<batch:step id = “step1”>

<batch:tasklet>

<batch:chunk reader = “ReaderOne” writer = “WriterOne”

processor = “ProcessorOne” commit-interval = “8”>

</batch:chunk>

</batch:tasklet>

</batch:step>

<batch:step id = “step2”>

<batch:tasklet>

<batch:chunk reader = “ReaderTwo” writer = “WriterTwo”

processor = “ProcessorTwo” commit-interval = “8”>

</batch:chunk>

</batch:tasklet>

</batch:step>

</batch:job>

<ถั่ว id =”ReaderOne” class =”org.springframework.batch.item.file.FlatFileItemReader”>

<!– Reading file–>

<property name=”resource” value=”classpath:cvs/sample.1csv” />

<property name=”lineMapper”>

<bean class=”org.springframework.batch.item.file.mapping.DefaultLineMapper”>

<!– splitting it –>

<property name=”lineTokenizer”>

<ถั่ว

class =”org.springframework.batch.item.file.transform.DelimitedLineTokenizer”>

<property name=”names” value=”date,impressions,clicks,earning” />

</ถั่ว>

</คุณสมบัติ>

<property name=”fieldSetMapper”>

<ถั่ว

class =”org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper”>

<property name=”prototypeBeanName” value=”samplereport” />

</ถั่ว>

</คุณสมบัติ>

</ถั่ว>

</คุณสมบัติ>

</ถั่ว>

<bean id = “WriterOne”

class = “org.springframework.batch.item.xml.StaxEventItemWriter”>

<property name = “resource” value = “ไฟล์:xml/outputs/sample1.xml” />

<property name = “marshaller” ref = “yyy” />

<property name = “rootTagName” value = “xxx” />

</ถั่ว>

<ถั่ว id =”ReaderTwo” class =”org.springframework.batch.item.file.FlatFileItemReader”>

<!– Reading file–>

<property name=”resource” value=”classpath:cvs/sample2.csv” />

<property name=”lineMapper”>

<bean class=”org.springframework.batch.item.file.mapping.DefaultLineMapper”>

<!– splitting it –>

<property name=”lineTokenizer”>

<ถั่ว

class =”org.springframework.batch.item.file.transform.DelimitedLineTokenizer”>

<property name=”names” value=”date,impressions,clicks,earning” />

</ถั่ว>

</คุณสมบัติ>

<property name=”fieldSetMapper”>

<ถั่ว

class =”org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper”>

<property name=”prototypeBeanName” value=”samplereport” />

</ถั่ว>

</คุณสมบัติ>

</ถั่ว>

</คุณสมบัติ>

</ถั่ว>

<bean id = “WriterTwo”

class = “org.springframework.batch.item.xml.StaxEventItemWriter”>

<property name = “resource” value = “ไฟล์:xml/outputs/sample2.xml” />

<property name = “marshaller” ref = “zzz” />

<property name = “rootTagName” value = “mmm” />

</ถั่ว>

</ถั่ว>

Now, we will be writing the main program to execute the batch job.

Listing 3: โปรแกรมหลักเพื่อรันงานแบ็ตช์,,en,นำเข้า org.springframework.batch.core.Job,,en,นำเข้า org.springframework.batch.core.JobExecution,,en,นำเข้า org.springframework.batch.core.JobParameters,,en,นำเข้า org.springframework.batch.core.launch.JobLauncher,,en,BatchAppRun ระดับสาธารณะ,,en,springAppConfig =,,en,งาน / helloTechAlpine.xml,,en,สร้างบริบทแอปพลิเคชัน,,en,springAppConfig,,en,สร้างตัวเรียกใช้งาน,,en,JobLauncher samplejobLauncher =,,en,JobLauncher,,en,jobLauncher,,en,สร้างงาน,,en,ตัวอย่างงาน,,en,งาน,,en,ดำเนินการ JOB,,en,การเรียกใช้งาน JobExecution = samplejobLauncher.run,,en,samplejob,,en,ใหม่ JobParameters,,en,การเรียกใช้งานไฟล์นี้จะเริ่มต้นงานแบ็ตช์และทำการประมวลผลไฟล์,,en,บริการสปริงแบทช์แก้ปัญหาธุรกิจขนาดใหญ่สำหรับองค์กรเพราะช่วยให้พวกเขาประหยัดทรัพยากรและทำสิ่งต่าง ๆ ได้อย่างรวดเร็ว,,en,สำคัญมาก,,en,มันเป็นโอเพนซอร์สและพร้อมสำหรับการปรับแต่ง,,en.

import org.springframework.batch.core.Job;

import org.springframework.batch.core.JobExecution;

import org.springframework.batch.core.JobParameters;

import org.springframework.batch.core.launch.JobLauncher;

นำเข้า org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BatchAppRun {

ประชาชนเป็นโมฆะหลักแบบคงที่(เชือก[] args) ยกเว้นพ่น {

เชือก[] springAppConfig = { “jobs/helloTechAlpine.xml” };

// Create application context

ApplicationContext context = new ClassPathXmlApplicationContext(springAppConfig);

// Create the job launcher

JobLauncher samplejobLauncher = (JobLauncher) context.getBean(“jobLauncher”);

// Crete the job

Job samplejob = (Job) context.getBean(“batchJobSample”);

// Execute the JOB

JobExecution execution = samplejobLauncher.run(samplejob, new JobParameters());

}

}

Executing this file will launch the batch job and do the file processing.

Must read – Interesting articles on Spring framework








ข้อสรุป

The Spring Batch services solves huge business problems for enterprises because it helps them save resources and get things done quickly. Very importantly, it is open source and available for customization. งานแบ็ตช์มีความสำคัญเมื่อคุณต้องการเขียนบางงานซ้ำ ๆ และเรียงตามลำดับ,,en,คุณเพียงแค่ต้องกำหนดหนึ่งครั้งในไฟล์กำหนดค่าแล้วเรียกใช้,,en,นั่นคือทั้งหมดที่เกี่ยวกับบริการชุดสปริง,,en,techalpine.com/steps-to-learn-spring-batch-service,,en. You just need to define them once in the configuration file and then run it. That’s all about Spring batch services.


============================================= ============================================== ซื้อหนังสือ techalpine ที่ดีที่สุดใน Amazon,en,ช่างไฟฟ้า CT Chestnutelectric,en
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share