5.2.1. Architecture Overview

The type of messaging process that treats a database as a queue provides the function to monitor tables on a database periodically and sequentially process records that are yet to be processed.

Important

Determination of the record that are not processed should be displayed on the table record. For that reason, it is necessary to perform the process of changing the status of the record for which processing is completed to processed

5.2.1.1. Configuration

It has the same structure as the Nablarch batch application. For details, see structure of Nablarch batch application

5.2.1.2. Specify action and request ID based on request path

For messaging process that treats the databases as a queues, specify the actions and request IDs to be executed using command line arguments as in the Nablarch batch application.

For details, see specify nablarch batch application action and request id .

5.2.1.3. Process flow

The process flow is the same as the Nablarch batch application. For details, see Process flow of Nablarch batch application .

5.2.1.4. Handler used

Nablarch provides several handlers as standard that are required for the messaging process that treats databases as a queues. Build the handler queue in accordance with the requirements of the project (a custom handler will have to be created for the project depending on the requirements)

For details of each handler, refer to the link.

Handlers that convert request and response
Handlers that control execution
Handlers associated with database
Error handling handler
Others

5.2.1.5. Minimum configuration of handler

The following shows the minimum required handler queue for messaging process that handles databases as queues. With this as the base, add standard handlers of Nablarch or custom handlers created in the project according to the project requirements.

Minimum handler configuration
No. Handler Thread Request process Response process Exception handling
1 Status Code → Process End Code Conversion Handler Main   Converts the status code to process exit code.  
2 Thread Context Variable Delete Handler Main   Deletes all the values configured on the thread local by the Thread Context Variable Management Handler .  
3 Global Error Handler Main     Outputs the log for a runtime exception or error.
4 Thread Context Variable Management Handler Main Initializes thread context variables such as request ID and user ID from command line arguments.    
5 Retry Handler Main     Catches a runtime exception that can be retried, and provided that the retry limit has not been reached, re-executes the subsequent handler.
6 Database Connection Management Handler (For initial processing/end processing) Main Acquires DB connection. Releases the DB connection.  
7 Transaction Control Handler (For initial processing/end processing) Main Begin a transaction Commits the transaction. Rolls back a transaction.
8 Request Dispatch Handler Main Determine the action to call based on the command line arguments.    
9 Multi-thread Execution Control Handler Main Creates a sub-thread and executes the process of the subsequent handler in parallel. Waits for normal termination of all threads. Waits for the current thread to complete and rethrows the cause exception.
10 Database Connection Management Handler (For business processing) Sub Acquires DB connection. Releases the DB connection.  
11 Loop Control Handler in Request Thread Sub   Delegates the process to the subsequent handler again. Performs the log output process and resend according to the exception/error.
12 Process Stop Control Handler Sub If the process stop flag of the request table is on, a process stop exception (ProcessStop) is thrown without performing the subsequent handler process.    
13 Data Read Handler Sub Use a data reader to read records one by one and pass it as an argument of the subsequent handler. Also, the execution ID numbered is numbered.   After generating output of the read record as a log, rethrows the original exception.
14 Transaction Control Handler (for business processing) Sub Begin a transaction Commits the transaction. Rolls back a transaction.

5.2.1.6. Data reader used

Use the following data reader to handle a database as a queue. Note that the the table cannot be monitored repeatedly if batch DatabaseRecordReader is used.

Important

If the requirements cannot be satisfied with the above mentioned reader, then the reader has to be created in the project based on the following points.

  • Even if the target data disappears, the reader should be able to continuously monitor the target data.
  • When used in a multithreaded environment, prevent the same data from being processed by multiple threads.
DatabaseTableQueueReader is implemented as given below to satisfy the above criteria
  • When there is no unprocessed data in the table, executes the search SQL again to extract the unprocessed data.
  • To ensure that multiple threads are not processing the same data, holds the identifier (primary key value) of the data currently being processed and reads data that has not been processed.

5.2.1.7. Template class of the action to use

Use the following template class to handle a database as a queue.