IBM Support

MQ sample "blast", enhancement for amqsblst which includes persistent messages

Question & Answer


Question

Is there an MQ sample program that is able to PUT/GET a specified number of messages, of a given size, with, or without persistence, within, or without a Unit Of Work, with, or without delays?

Answer

This article provides a sample called "blast" that is based on the MQ sample "amqsblst.c".
++ Attachement
The following attached zip file ...
... provides these 3 files:
blast.c => source code (the header contains a lot of information!)
blast => bindings mode, compiled on Linux x86-64, RHEL 8.6, MQ 9.2
blastc => network client mode, compiled on Linux x86-64, RHEL 8.6, MQ 9.2
++ Version history
1.1 - 19-Mar-2021 - initial delivery
1.2 - 28-Jul-2022 - update for RHEL 8.6
++ Sample usage
 Using Queue Manager QM92, queue Q1
   . /opt/mqm92/bin/setmqenv -s
   echo "dis ql(Q1) curdepth" | runmqsc QM92
 To write (-W) 100 messages (-n 100) with a size of 64 bytes (-s 64)
   ./blast -W -m QM92 -q Q1 -n 100 -s 64 
   Blast> Elapsed time = 0.011468 seconds
   Blast> 100 messages successfully written.
   echo "dis ql(Q1) curdepth" | runmqsc QM92 | grep CURDEPTH
     CURDEPTH(100)
 To read (-R) 95 messages (-n 95)
   ./blast -R -m QM92 -q Q1 -n 95
   Blast> Elapsed time = 0.003022 seconds
   Blast> 95 messages successfully read.
   echo "dis ql(Q1) curdepth" | runmqsc QM92 | grep CURDEPTH
     CURDEPTH(5)
To write (-W) 1 message (-n 1), which is persistent (-p), within a Unit of Work of 1 message (-u 1) with a delay of 20 seconds between the put and the commit (-d 20) and verbose (-v).
  ./blast  -m QM92 -q Q1 -W -n 1 -u 1 -d 20 -p -v

++ Usage information
The new sample has the following "usage" information:
blast - Usage information
Required and mutually exclusive arguments:
--------------+--------------------------------------------------
-R            | Read  (GET messages)
-W            | Write (PUT messages)
--------------+----------------------------------------+---------
Required arguments:                                    | Notes
--------------+----------------------------------------+---------
-m QMname     | Queue Manager (QM) name                | 4
-q QName      | Queue name                             |
--------------+----------------------------------------+---------
Optional arguments:
--------------+-------------------------+--------------+---------
   Option     | Description             | Value limits | Notes
--------------+-------------------------+--------------+---------
-C CorrelId   | Correlator Id           | 0..24 chars  | 5
-d delay      | Put delay (seconds)     | [0..600]     | 10
-G GroupId    | Group Id                | 0..24 chars  | 5
-L            | Logical Order (groups)  |              | 11
-n msgCount   | # of messages           | [1..1g]      | 1,2
-P Interval   | Progress Interval       | [10..100m]   | 1,3,8
-p            | Persistent              |              |
-s size       | Message size (bytes)    | [1..100M]    | 1,7
-U Userid     | When one is required.   |              | 12
-u UoWsize    | # of messages in UoW    | [0..10m]     | 1,9
-v            | Verbose (debug)         |              |
-w waitInt    | GET Wait Interval (sec) | [0..120]     | 6
--------------+-------------------------+--------------+---------
-? | -h       | Display this usage information
--------------+--------------------------------------------------
Notes:
 1. The size values (e.g., -n, -P, ...) allow an optional suffix
    letter.  One of:  k,m,g,K,M,G.
    Where:
    k = 1000, m = 1,000,000, and g = 1E9 (powers of 10), and
    K = 1024, M = 1024 ** 2, & G = 2**30 (i.e., powers of 2).
 2. Even though the number of messages is allowed to be specified
    as 1 to 1 billion (i.e., 1,000,000,000), it is unlikely that
    the MQ environment will be able to handle this many messages.
 3. The Progress Indication interval specifies how often progress
    messages should be displayed.  Thus, -P 10k would mean that
    progress messages should be displayed after every 10,000
    messages.
 4. If you want to use the "default" Queue Manager, then it
    should be specified as -m "".
 5. The Correlator and Group ID values can be simple text string,
    (e.g., "Testing").  However, if either sequence contains
    only hexadecimal characters (i.e., 0 through 9, and the
    letters A through F, or lowercase a through f) then this
    sequence will be converted to the binary value that is
    equivalent to the specified sequence of hexadecimal digits.
    Example: -C 414d5120434f4e54524f4c20202020209f87d65e03910c21
    Note: These values should be no more than 24 characters long
    which is equivalent to 48 hexadecimal digits in length.
 6. The default wait interval is 120 seconds.
    Note: A value of 0 is interpreted as 120 seconds.
 7. The default message size is 0, which is equalent to 1024.
 8. The default Progress Indication interval is 0, which means
    that no progress messages will be displayed.
 9. The default Unit of Work (UoW) size is 0, which means that
    messages will not be sent under a Unit of Work.
10. The default Put delay is 0, which means that no delay will
    be used.
11. If a GroupID value is specified, messages in the group will
    be PUT in Physical order.  To override this, specify -L so
    Logical group order will be used, instead.
    Note: When READing messages, it is recommended that -L be
    specified.
12. When specifying Userid, you will be asked for the password.
++ How to compile the program
The header of the source file has the following section:
/* How to compile this sample in Linux
 * Note: The code has not been compiled under Windows
 *
 * See the following section in the online MQ manual:
 *  https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.2.0/com.ibm.mq.dev.doc/q028490_.htm
 *   IBM MQ 9.2.x / IBM MQ / Developing applications / Developing MQI applications with IBM MQ /
 *   Building a procedural application / Building your procedural application on Linux /
 *   Preparing C programs in Linux / Building 64-bit applications
 *
 * In particular for this sample, for Linux x86 64-bit 
 * where MQ 9.2 is installed in /opt/mqm92
 *
 * Setup the environment variables for MQ
      . /opt/mqm92/bin/setmqenv -s
 *
 * Bindings mode, C server application, 64-bit, threaded
 *   gcc -m64 -o blast  blast.c -I $MQ_INSTALLATION_PATH/inc -L $MQ_INSTALLATION_PATH/lib64 -Wl,-rpath=$MQ_INSTALLATION_PATH/lib64 -Wl,-rpath=/usr/lib64 -lmqm_r  -lpthread
 *
 * Clients mode, C client application, 64-bit, threaded:
 *   gcc -m64 -o blastc blast.c -I $MQ_INSTALLATION_PATH/inc -L $MQ_INSTALLATION_PATH/lib64 -Wl,-rpath=$MQ_INSTALLATION_PATH/lib64 -Wl,-rpath=/usr/lib64 -lmqic_r -lpthread
 *
 * gcc
 *   -m64                              : 64 bit
 *   -o blast blast.c                  : Output & Input filenames
 *   -I /opt/mqm92/inc                 : Include directory
 *   -L /opt/mqm92/lib64               : Link directory
 *   -Wl,-rpath=/opt/mqm92/lib64       : Linker option (start group)
 *   -Wl,-rpath=/usr/lib64             : Linker option (end   group)
 *   -lmqm_r | -lmqc_r                 : MQ "bindings" or "client" library
 *   -lpthread                         : Threaded library
 *----------------------------------------------------------------------------
 */
++ DISCLAIMER
   All source code and/or binaries attached to this document are referred to here as "the Program". 
   IBM is not providing program services of any kind for the Program. 
   IBM is providing the Program on an "AS IS" basis without warranty of any kind. 
   IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, 
   OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES 
   (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, 
   HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+++ end +++

[{"Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSYHRD","label":"IBM MQ"},"ARM Category":[{"code":"a8m0z00000008HMAAY","label":"Components and Features-\u003EApplication Programming"}],"ARM Case Number":"TS005090957","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Version(s)"}]

Document Information

Modified date:
28 July 2022

UID

ibm16437003