Tuesday, June 15, 2021

Getting to message queue data faster

getting data from message queue using sql table function faster than view

Prior to the latest round of Technology Refreshes for 7.4 and 7.3 if I wanted to get the data from a particular message queue I would need to use the MESSAGE_QUEUE_INFO SQL View. Being a View it contains all the data from all of the message queues, not just the one I would be interested. If I wanted to retrieve the messages from one message queue it would take a while for the results to be found and returned.

There is now a MESSAGE_QUEUE_INFO Table function. Table functions are faster than Views as they are sort of like an API, I pass the message queue name to the Table function and only that message queue is searched for the information I want.

The results returned by the View and Table function are almost identical. The only difference is that the View returns columns for the name of the message queue and the library it resides. As I pass that information to the Table function it is irrelevant to its results.

MESSAGE_QUEUE_INFO Table function has four parameters:

  1. QUEUE_LIBRARY:  Name of the library containing the message queue. This is optional, if no value is given the QSYS is assumed
  2. QUEUE_NAME:  Name of the message queue. This is optional, if none is given QSYSOPR is assumed
  3. MESSAGE_FILTER:  Allowed values
    • ALL:  All messages are returned, if no value is given this is the default
    • COMPLETE:  Message that do not require a reply only
    • INQUIRY:  Message that require a reply only
    • SENDER:  Copies of the inquiry messages that were sent to other message queues and still require a reply
  4. SEVERITY_FILTER:  Message severity, which is values of 0 to 99. The default is 0

If I wanted to use this Table function to view the messages in my user profile's message queue I could use the following SQL statement:

)) ;

The results are returned in a blink of an eye:

----------  -------------  ------------  --------
<NULL>      INFORMATIONAL  Hello there!       80

I can get the same result without using the parameter names, and changing the message filter and severity filter values:


I think we all know I am not going to checking messages on my message queue very often. What I will be doing is checking for messages in the QSYSOPR message queue. All of the defaults for this Table function is set for QSYSOPR, so I can just use the following to see all the messages contained within that message queue:


If I am only interested in the messages that, for example, I generated using the SEND_MESSAGE SQL procedure I could use the following:

01  SELECT * 
05  LIMIT 1 ;

Line 2: By using the COMPLETE message filter I am only being returned messages that did not require a reply in the results.

Line 3: Then from those results I am only selecting those that have the message id that I created, "MINE123".

Line 5: And I am only returning one result.

The results are:

_ID      _TYPE          _TEXT           SEVERITY
-------  -------------  --------------  --------
MINE123  INFORMATIONAL  This is a test	       0

In my opinion the MESSAGE_QUEUE_INFO Table function is a great addition. While I will not be going through all my old programs and modules to replace where I have used the MESSAGE_QUEUE_INFO View. I will be using the Table function in anything new I do.


You can learn more about the MESSAGE_QUEUE_INFO SQL Table function from the IBM website here.


This article was written for IBM i 7.4 TR4, and will work for 7.3 TR10 too.


To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.