8.3.4. Initial Setup of the Nablarch Batch Project

The following is procedures of initial setup of the Nablarch batch project:

  • Generate the Nablarch batch project
  • Confirm communications of the Nablarch batch project

8.3.4.1. Overview of the generated project

The overview of the project generated by this procedure is as follows.

Item Description
Project type Maven project
Project composition Single project composition
DB used H2 Database Engine (embedded in the application)
What is included in the generated project?

The following is included in the generated project:

  • Basic configuration for the Nablarch batch application
  • On-demand batch application for communication confirmation
  • Messaging using tables as queues for communication confirmation
  • Email send batch configuration [1]
  • Initial configuration of the tool that operates in conjunction with Maven (is imported by referring to nablarch-archetype-parent (parent project)).
[1]Email send batch functions as a resident batch and sends mail to the SMTP server. Sample component configuration file is present in src/main/resources/mail-sender-boot.xml. Email send batch is not necessary when building the initial environment, but when it becomes necessary, use after reading the description of send email.

For relationship with other projects and directories, see Maven Archetype Configuration.

8.3.4.2. Create blank project

Generate a blank project using the archetypes provided by Nablarch.

8.3.4.2.1. Execute the mvn command

Change the current directory to the directory where the blank project (can be any directory) is to be created, and place the following file.

Batch file

After placing the file, specify the necessary parameters in the arguments and execute the bat file.

generateNablarchBatchProject.bat 5u24 <<groupId>> <<artifactId>> <<version>> <<package(optional)>>

The parameters configured in the above command are as follows. If you want to change the version of Nablarch, change 5u24. Change the current directory to the directory where the blank project (can be any directory) is to be created.

Input item Description Configuration example
groupId Group ID (normally, enter the package name) com.example
artifactId Artifact ID myapp-batch
version Version number 0.1.0
package Package (normally the same as group ID) com.example

Important

Item groupId and package are mapped to the Java package name. Use lowercase letters, numbers, and dots for these input values, and do not use hyphens.

If the command ends normally, a blank project is created under the current directory.

8.3.4.3. Communication confirmation (on-demand batch)

8.3.4.3.1. Automated test (on-demand batch)

The following unit tests are included in the project generated from the archetype.

Unit test classes Test content
SampleBatchActionRequestTest Use the Nablarch testing framework to check if the batch can be launched.

Execute the unit test and confirm that the blank project was successfully generated.

Execute the following command.

cd myapp-batch
mvn test

If the execution is successful, the log given below will be output to the console.

(omitted)
[INFO] ----------------------< com.example:myapp-batch >-----------------------
[INFO] Building myapp-batch 0.1.0
[INFO] --------------------------------[ jar ]---------------------------------
(omitted)
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
(rest is omitted)

8.3.4.3.2. Launch test (on-demand batch)

The on-demand batch is included in the generated project.

Batch class Details
SampleAction Confirm communications of the Nablarch functions commonly used when implementing batch applications.

Confirm that the blank project has been successfully generated by launching on-demand batch.

8.3.4.3.2.1. Build a batch application

If the current directory is not yet moved to the generated project, move the directory.

cd myapp-batch

Execute the following command to build the batch application.

mvn package

8.3.4.3.2.2. Launching the on-demand batch application

Execute the following command.

mvn exec:java -Dexec.mainClass=nablarch.fw.launcher.Main ^
    -Dexec.args="'-diConfig' 'classpath:batch-boot.xml' '-requestPath' 'SampleBatch' '-userId' 'batch_user'"

If the launch is successful, the log given below will be output to the console.

2020-04-28 08:56:23.353 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 疎通確認を開始します。
2020-04-28 08:56:23.379 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 取得したコード名称:ロック
2020-04-28 08:56:23.383 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 疎通確認が完了しました。
2020-04-28 08:56:23.396 -INFO- nablarch.fw.handler.MultiThreadExecutionHandler [202004280856233470001] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user]
Thread Status: normal end.
Thread Result:[200 Success] The request has succeeded.
2020-04-28 08:56:23.407 -INFO- nablarch.core.log.app.BasicCommitLogger [202004280856233470001] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] TOTAL COMMIT COUNT = [1]
2020-04-28 08:56:23.413 -INFO- nablarch.fw.launcher.Main [null] boot_proc = [] proc_sys = [batch] req_id = [null] usr_id = [null] @@@@ END @@@@ exit code = [0] execute time(ms) = [559]

8.3.4.4. Communication confirmation (messaging using tables as queues)

The following application is included in the generated project.

Batch class Details
SampleResiAction An application that implements the basic process “fetch values from the table to be processed and set a processed flag” of messaging using a table as a queue

Confirm that the blank project has been successfully generated by launching the above application.

8.3.4.4.1. Launch test (messaging using tables as queues)

8.3.4.4.1.1. Build an application

If it has not yet been built, see Build a batch application and build.

8.3.4.4.1.2. Launch the application

Execute the following command.

mvn exec:java -Dexec.mainClass=nablarch.fw.launcher.Main ^
    -Dexec.args="'-diConfig' 'classpath:resident-batch-boot.xml' '-requestPath' 'SampleResiBatch' '-userId' 'batch_user'"

Tip

The differences between the above arguments and the on-demand batch application are as follows.

  • xml file specified by -diConfig
  • Request path specified by -requestPath

If the launch is successful, the log given below will be output to the console.

2020-04-28 08:58:15.350 -INFO- nablarch.fw.reader.DatabaseTableQueueReader [202004280858153390001] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] read database record. key info: {USER_INFO_ID=00000000000000000001}
2020-04-28 08:58:15.356 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] handleが呼ばれました。
2020-04-28 08:58:15.363 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] USER_INFO_ID:00000000000000000001
2020-04-28 08:58:15.367 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] LOGIN_ID:TAROU
2020-04-28 08:58:15.371 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] KANA_NAME:たろう
2020-04-28 08:58:15.379 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] KANJI_NAME:太郎

Forcibly terminate with ctrl + c.

Important

Nablarch assumes that the correct way to exit is to use the BATCH_REQUEST table The method is to set the flag of PROCESS_HALT_FLG to 1. In this procedure, we use ctrl + c to stop it for simplicity.

If you want to restart the messaging with the table as a queue after the termination, see To Restart Messaging Using Tables as Queues.

8.3.4.4.2. If the communication confirmation fails for some reason

If the communication confirmation fails for some unknown reason, the correct procedure may not have been followed in some part.

If the reason is not known, try again from Create blank project.

8.3.4.5. Supplementary notes

For information on the method of confirming the data of H2 and tools included in the blank project, see Initial Setup Procedure Supplementary Information.