MQ Messages to/from SQLite DB

Capitalware has an MQ solution called MQ Message Replication (MQMR).

MQ Message Replication will clone messages being written (via MQPUT or MQPUT1 API calls) to an application’s output queue and MQMR will write the exact same messages to ‘n’ target queues (‘n’ can be up to 100). When MQMR replicates a message both the message data and the message’s MQMD structure will be cloned. This means that the fields of the MQMD structure (i.e. PutTime, MessageId, CorrelId, UserId, etc..) will be exactly the same as the original message’s MQMD structure.

I have always left it up to the customer to decide what to do with and/or how to offload replicated messages in the target queue(s). There are probably 100 solutions for extracting messages in a queue and writing the information to a file: Capitalware has solutions, other vendors have products, SupprtPacs and even the new dmpmqmsg program included with IBM MQ. These are all fine tools to get the job done and of course, I prefer my tools which use VEQ format that I created a very long time ago (and is published here).

Over this past weekend, I got the bright idea to create the 101st solution for offloading and loading MQ messages to and from an SQLite database. I will include the solution with MQMR for free – an extra little bonus for customers. 🙂

Why bother? Well, it is nice to have MQ messages as records in a database table. It allows the user to do what ever they want to the MQMD header and/or the message data. There are lots of SQLite tools to manage/interact with an SQLite database. Plus, an SQLite database is a single file. So, a user can quickly compress/zip the file and move it another server without any issues.

I like the KISS (Keep It Simple Stupid) principle. So rather than have 1 program do both loading and unloading of messages, I broke it up into 2 light-weight programs. Ok, light-weight may be a bit of an understatement since they both have MQ and database calls. 🙂

  • MQ Queue To SQLite DB (MQ2SDB) program will offload MQ messages to an SQLite database.
  • SQLite DB To MQ Queue (SDB2MQ) program will load SQLite database rows into messages in an MQ queue.

I decided to write these 2 programs in C rather than Java. I like to mix things up. 🙂 I’ll do builds of them on AIX, HP-UX, IBM i, Linux, Solaris and Windows.

Both programs can be run from the command line or as an MQ Service. I would strongly suggest that people run MQ2SDB program as an MQ Service on the same queue manager where MQMR is configured as an MQ API Exit. Hence, when the queue manager is started, MQ2SDB will write MQ messages to the SQLite database right away.

MQ2SDB program will create the database file based on the queue manager’s name, the queue name and the current day’s date.
I.e.
{QMgrName}-{QueueName}-YYYY_MM_DD.mqsdb

When retrieving MQ messages and writing them to an SQLite database, MQ2SDB program will automatically roll to the next file at midnight (or when the next message arrives after midnight).

Here’s a screen-shot of DB Browser for SQLite with an SQLite database table that contains 100 records (messages). Click to see a larger image of it.


By default, when the SDB2MQ program is run, it will load all of the records in the database table as messages into the specified queue. The SDB2MQ program has 2 optional parameters (StartPosition and RowCount) to control where to start the load and how many records to load as messages into the queue.

If you interesting in trying it out, please send an email to support@capitalware.com to request a trial of MQ Message Replication with these new extra tools.

Note: If people are interested in offload/load messages to/from an SQLite database then I will extend this feature into MQ Visual Edit, MQ Visual Browse and MQ Batch Toolkit.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in Capitalware, Database, IBM i (OS/400), IBM MQ, Linux, MQ Message Replication, Unix, Windows.

Comments are closed.