Nrhiav kom paub cov kev pab Batch caij nplooj ntoos hlav

Spring Batch Service

Caij nplooj ntoos hlav Batch Service – Nws yuav ua li cas?

Txheej txheem cej luam :

Tus Caij nplooj ntoos hlav batch kev pab automate ua cov hauj lwm ntau rau hauv cooling. Nws yog ib qhov hau uas muaj cov APIs thiab cov kev pab uas tau yuav reused mus ua ntaub ntawv dua hauj lwm hauv cooling. Ntawm ib seem yus pom enterprise, Caij nplooj ntoos hlav muaj caij nyoog optimize cov chaw muab kev pab thiab kev txuag nqi ruaj vim hais tias cov kev pab cuam batch caij nplooj ntoos hlav tau ntaub ntawv ntau txoj hauj lwm sai sai. Xav tias cov no – ib enterprise tsis tau los ntiav cov manpower rau txim tuag repetitive hauj lwm. Xwb, cov hauj lwm uas yuav tau ua los ntawm ib moj qhib qhov khaum uas muab npaj ua APIs thiab cov kev pab thiab tau tso cai rau cov kev hloov kho cov kev pab cuam as per yuav tsum tau.








Caij nplooj ntoos hlav batch yog dab tsi?

Qhauj tau ntaub ntawv ntau lag xws li lus teb hli kawg, hauj lwm thiab thov ua hauj lwm txoj cai thiab integrating txoj lus tau los ntawm lwm qhov chaw tiav repetitively nyob loj teeb ua khub tej uas tsawg heev los yog tsis muaj kev pab tib neeg. Lub caij nplooj ntoos hlav Batch puas raws nraim uas. Lub caij nplooj ntoos hlav batch, Nws yog ib feem ntawm cov Caij nplooj ntoos hlav portfolio, yog muaj moj qhib qhov khaum uas tso cai rau qhov kev loj hlob ntawm daim ntaub ntawv batch-ua. Caij nplooj ntoos hlav Batch muaj peevxwm mus xyuas leej yooj yooj yim thiab txoj lag. Thaum nws muaj reusable zog uas tau ntaub ntawv loj tagnrho ntawm cov ntaub ntawv nrog rau cov tswj lw, ua hauj lwm txheeb cais, txiav/tracing, hla, txoj hauj lwm Updated 10/22/07/f.Triplett thiab kev pab tswj, Nws kuj muaj kev pab thiab nta uas pab kom muaj kev kawm ntawv qib high school-ntim thiab siab batch hauj lwm los ntawm optimization thiab partitioning rau hom kev kawm.

Ib qho twg rau lub caij nplooj ntoos hlav batch architecture muaj ib tug hais ua si. Daim ntawv thov Batch tivthaiv yog cov ntawv uas tso cai rau cov developers software rau batch txheej txheem hauj lwm dua. Lub caij nplooj ntoos hlav Batch ntxhais muab runtime nyob rau daim ntawv thov Batch. Ntsig, lub caij nplooj ntoos hlav Batch Infrastructure muaj cov hoob pab tau rau ob lub tsev thiab khiav batch apps.

Yuav tsum saib – Caij nplooj ntoos hlav video tutorials

Zoo

Ntawm qhov seem yus pom enterprise, Nws yog tej uas lag los yog hauj lwm tiav expected laij thiab tsis pub dhau lub sij hawm. Qhauj xav sau ntau li haujlwm kom sai sai tau nrog lub peev ntawm cov chaw muab kev pab uas yuav muaj lub sij hawm thiab cov neeg ua hauj lwm tsawg. Lub caij nplooj ntoos hlav batch kev tso cai rau cov enterprise mus cuag cov hom phiaj no. Lub ntsiab zoo lub caij nplooj ntoos hlav batch kev pab raug muab hauv qab.

  • Nyob rau ntawm qhov reusable zog uas yuav ua tau paub tab xws li zauv loj tagnrho ntawm cov ntaub ntawv uas muaj logging/tracing, lw, thiab txoj hauj lwm xyuas txog kev txheeb cais, Updated 10/22/07/f.Triplett txoj hauj lwm, hla, thiab fwm.
  • Nyob rau ntawm qhov kev pab uas yuav ua tau txoj kev pab raws qib uas raus cov hauj lwm uas ntim High School thiab qib kev kawm batch.
  • Thaum lub caij, Caij nplooj ntoos hlav batch cov kev pab no tej zaum cov zoo muaj tshuaj, kom deb li deb ntawm batch ua hauj lwm yuav txhawj.









Kev pab tsim lub caij nplooj hlav Batch

Ua ntej tsim muaj ib qhov Java siv Maven

$ mvn archetype:ua kom muaj - DgroupId=com.techalpine - DartifactId = ExampleSpringBatch

-DarchetypeArtifactId = maven-archetype-quickstart - DinteractiveMode = cuav

Tam sim no, mus kom txhob hais kom ua thiab siv nws tau ib qhov dab noj hnub thiab ntshuam hauv dab noj hnub IDE. Follow the commands shown below.

cd ExampleSpringBatch/

$ mvn eclipse:eclipse

Declare all project dependencies in pom.xml as shown below.

Qhia 1: Defining pom.xml with dependencies

<picture of Kathy 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.com techalpine</groupId>

<artifactId>ExampleSpringBatch</artifactId>

<packaging>hwj iav</packaging>

<Version>1.0-SNAPSHOT</Version>

<lub npe>ExampleSpringBatch</lub npe>

<url>http://maven.apache.org</url>

<khoom>

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

<spring.version>3.2.2.TSO TAWM</spring.version>

<spring.batch.version>2.2.0.TSO TAWM</spring.batch.version>

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

</khoom>

<dependencies>

<!– Spring Core –>

<quav dej caws>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

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

</quav dej caws>

<!– Spring jdbc, for database –>

<quav dej caws>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

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

</quav dej caws>

<!– Spring Batch dependencies –>

<quav dej caws>

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

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

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

</quav dej caws>

<quav dej caws>

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

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

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

</quav dej caws>

<!– MySQL database driver –>

<quav dej caws>

<groupId>mysql</groupId>

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

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

</quav dej caws>

</dependencies>

<lawv muaj>

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

<plugins>

<plugin>

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

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

<Version>2.9</Version>

<configuration>

<downloadSources>tseeb</downloadSources>

<downloadJavadocs>tsis tseeb</downloadJavadocs>

</configuration>

</plugin>

<plugin>

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

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

<Version>2.3.2</Version>

<configuration>

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

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

</configuration>

</plugin>

</plugins>

</lawv muaj>

</yog ib qhov>



Tam sim no, defining batch jobs. This section defines sequence of batch jobs. Steps are mentioned as ‘step1′,’step2’ yam. 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.

Qhia 2: Describing batch jobs and components

<taum xmlns =”http://www.springframework.org/schema/beans”

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

xmlns:task=”http://www.springframework.org/schema/task

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”>

<taum daim id =”samplereport” hoob =”com.techalpine.spring.batchscope=prototype” />

<batch:job id =batchJobSample”>

<batch:step id =step1”>

<batch:tasklet>

<batch:chunk reader =ReaderOnewriter =WriterOne

processor =ProcessorOnecommit-interval = “8”>

</batch:chunk>

</batch:tasklet>

</batch:kauj ruam>

<batch:step id =step2”>

<batch:tasklet>

<batch:chunk reader =ReaderTwowriter =WriterTwo

processor =ProcessorTwocommit-interval = “8”>

</batch:chunk>

</batch:tasklet>

</batch:kauj ruam>

</batch:job>

<taum daim id =”ReaderOne” hoob =”org.springframework.batch.item.file.FlatFileItemReader”>

<!– Reading file–>

<lub npe ntawm tus kheej =”qhov chaw muab kev pab” tus nqi =”classpath:cvs/sample.1csv” />

<lub npe ntawm tus kheej =”lineMapper”>

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

<!– splitting it –>

<lub npe ntawm tus kheej =”lineTokenizer”>

<taum

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

<lub npe ntawm tus kheej =”npe” tus nqi =”hnub,impressions,clicks,earning” />

</taum>

</khoom>

<lub npe ntawm tus kheej =”fieldSetMapper”>

<taum

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

<lub npe ntawm tus kheej =”prototypeBeanName” tus nqi =”samplereport” />

</taum>

</khoom>

</taum>

</khoom>

</taum>

<taum = “WriterOne

Hoob Kawm = “org.springframework.batch.item.xml.StaxEventItemWriter”>

<cuab yeej ntawm tus kheej = “qhov chaw muab kev pab” tus nqi = “cov ntaub ntawv:xml/outputs/sample1.xml” />

<cuab yeej ntawm tus kheej = “marshaller” nyob = “yyy” />

<cuab yeej ntawm tus kheej = “rootTagName” tus nqi = “xxx” />

</taum>

<taum daim id =”ReaderTwo” hoob =”org.springframework.batch.item.file.FlatFileItemReader”>

<!– Reading file–>

<lub npe ntawm tus kheej =”qhov chaw muab kev pab” tus nqi =”classpath:cvs/sample2.csv” />

<lub npe ntawm tus kheej =”lineMapper”>

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

<!– splitting it –>

<lub npe ntawm tus kheej =”lineTokenizer”>

<taum

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

<lub npe ntawm tus kheej =”npe” tus nqi =”hnub,impressions,clicks,earning” />

</taum>

</khoom>

<lub npe ntawm tus kheej =”fieldSetMapper”>

<taum

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

<lub npe ntawm tus kheej =”prototypeBeanName” tus nqi =”samplereport” />

</taum>

</khoom>

</taum>

</khoom>

</taum>

<taum = “WriterTwo

Hoob Kawm = “org.springframework.batch.item.xml.StaxEventItemWriter”>

<cuab yeej ntawm tus kheej = “qhov chaw muab kev pab” tus nqi = “cov ntaub ntawv:xml/outputs/sample2.xml” />

<cuab yeej ntawm tus kheej = “marshaller” nyob = “zzz” />

<cuab yeej ntawm tus kheej = “rootTagName” tus nqi = “mmm” />

</taum>

</taum>

Tam sim no, peb yuav tsum sau qhov kev pab cuam tseem ceeb rau txim tuag rau txoj hauj lwm batch.

Qhia 3: Lub ntsiab kev khiav hauj lwm batch.

ntshuam org.springframework.batch.core.Job;

ntshuam org.springframework.batch.core.JobExecution;

ntshuam org.springframework.batch.core.JobParameters;

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

ntshuam org.springframework.context.ApplicationContext;

ntshuam org.springframework.context.support.ClassPathXmlApplicationContext;

tsev kawm BatchAppRun {

pej xeem tsis muaj dabtsis loj zoo li qub(Txoj hlua[] args) throws kos {

Txoj hlua[] springAppConfig = { “jobs/helloTechAlpine.xml” };

// Sau cov ntsiab lus teb daim ntawv thov

ApplicationContext lub ntsiab lus teb = ClassPathXmlApplicationContext tshiab(springAppConfig);

// Ua tau ib txoj hauj lwm launcher

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

// Crete cov hauj lwm

Txoj hauj lwm samplejob = (Txoj hauj lwm) context.getBean(“batchJobSample”);

// Coj cov hauj lwm

Tso JobExecution = samplejobLauncher.run(samplejob, JobParameters tshiab());

}

}

Executing tej ntaub ntawv no yuav tso cov hauj lwm batch thiab ua cov ntaub ntawv ua.

Yuav tsum nyeem – Nthuav cov khoom rau lub caij nplooj ntoos hlav moj khaum








Xaus

Lub caij nplooj ntoos hlav Batch services solves teeb meem ua lag ua luam loj loj rau qhauj vim yuav pab kom tseg cov kev pab thiab tau txais yam uas ua sai sai. Ceeb heev tshaj, nws yuav qhib tau qhov twg los thiab muaj customization. Batch hauj lwm tseem ceeb thaum koj yuav tau sau ib co kev pab raws qib pheej thiab lawv. Koj nyuam qhuav tau txhais tau lawv ib zaug rau hauv configuration thiab ces tso nws. Li no txog tej kev pab batch caij nplooj ntoos hlav.


============================================= ============================================== Yuav zoo TechAlpine phau ntawv rau Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Txaus siab rau qhov blog? Tshaj tawm lus thov :)

Follow by Email
LinkedIn
LinkedIn
Share