Database coordination samples

 

Two samples are provided that demonstrate how WebSphere MQ can coordinate both WebSphere MQ updates and database updates within the same unit of work:

  1. AMQSXAS0 (in C) or AMQ0XAS0 (in COBOL), which updates a single database within a WebSphere MQ unit of work.

  2. AMQSXAG0 (in C) or AMQ0XAG0 (in COBOL), AMQSXAB0 (in C) or AMQ0XAB0 (in COBOL), and AMQSXAF0 (in C) or AMQ0XAF0 (in COBOL), which together update two databases within a WebSphere MQ unit of work, showing how multiple databases can be accessed. These samples are provided to show the use of the MQBEGIN call, mixed SQL and WebSphere MQ calls, and where and when to connect to a database.

Figure 1 shows how the samples provided are used to update databases:

Figure 1. The database coordination samples

The programs read a message from a queue (under syncpoint), then, using the information in the message, obtain the relevant information from the database and update it. The new status of the database is then printed.

The program logic is as follows:

  1. Use the name of the input queue from the program argument

  2. Connect to the default queue manager (or optionally the supplied name in C) using MQCONN

  3. Open a queue (using MQOPEN) for input while there are no failures

  4. Start a unit of work using MQBEGIN

  5. Get the next message (using MQGET) from the queue under syncpoint

  6. Get information from databases

  7. Update information from databases

  8. Commit changes using MQCMIT

  9. Print updated information (no message being available counts as a failure, and the loop ends)

  10. Close the queue using MQCLOSE

  11. Disconnect from the queue using MQDISC

SQL cursors are used in the samples, so that reads from the databases (that is, multiple instances) are locked while a message is being processed, allowing multiple instances of these programs to run simultaneously. The cursors are explicitly opened, but implicitly closed by the MQCMIT call.

The single database sample (AMQSXAS0 or AMQ0XAS0) has no SQL CONNECT statements and the connection to the database is implicitly made by WebSphere MQ with the MQBEGIN call. The multiple database sample (AMQSXAG0 or AMQ0XAG0, AMQSXAB0 or AMQ0XAB0, and AMQSXAF0 or AMQ0XAF0) has SQL CONNECT statements, as some database products allow only one active connection. If this is not the case for your database product, or if you are accessing a single database in multiple database products, the SQL CONNECT statements can be removed.

The samples are prepared with the IBM DB2 database product, so you might need to modify them to work with other database products.

The SQL error checking uses routines in UTIL.C and CHECKERR.CBL supplied by DB2. These must be compiled or replaced before compiling and linking.

If you are using the Micro Focus COBOL source CHECKERR.MFC for SQL error checking, change the program ID to uppercase, that is CHECKERR, for AMQ0XAS0 to link correctly.

 

Parent topic:

Sample programs (all platforms except z/OS)


fg17710_