Request & Reply JMS/MQRFH2 Messaging Scenario

Sometimes people over think a problem and write a complicated solution when really the solution is no different than any other Request/Reply scenario (use case).

On StackOverflow, someone asked a question about sending a reply JMS/MQRFH2 message using the RFH2 header and folder values from the original request message.

The code will copy the RFH2 header and folders from the request message to the reply message.

I did 3 extra things:

(1) Updated the destination queue name in the “jms” folder.

(2) Set the reply message’s Correlation Id to contain the request message’s Message Id.

(3) Used the checksum of the request message’s payload as a seed value for the random number generator that generated Powerball numbers for the reply message’s payload.

You can download the source code from here.

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.Random;
import java.util.zip.CRC32;
import java.util.zip.Checksum;

import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.headers.MQDataException;
import com.ibm.mq.headers.MQRFH2;

/**
 * Program Name
 *  MQTest77
 *
 * Description
 *  This java class will connect to a remote queue manager with the MQ setting stored in a HashTable.
 *  It will get a request MQRFH2 message from an input queue and then send a reply MQRFH2 message.
 *
 * Sample Command Line Parameters
 *  -m MQA1 -h 127.0.0.1 -p 1414 -c TEST.CHL -q INPUT.Q1 -o OUTPUT.Q1 -u UserID -x Password
 *
 * @author Roger Lacroix
 */
public class MQTest77
{
   private static final SimpleDateFormat  LOGGER_TIMESTAMP = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");

   private Hashtable<String,String> params;
   private Hashtable<String,Object> mqht;
   private String qMgrName;
   private String inputQName;
   private String outputQName;

   /**
    * The constructor
    */
   public MQTest77()
   {
      super();
      params = new Hashtable<String,String>();
      mqht = new Hashtable<String,Object>();
   }

   /**
    * Make sure the required parameters are present.
    * @return true/false
    */
   private boolean allParamsPresent()
   {
      boolean b = params.containsKey("-h") && params.containsKey("-p") &&
                  params.containsKey("-c") && params.containsKey("-m") &&
                  params.containsKey("-q") && params.containsKey("-o") &&
                  params.containsKey("-u") && params.containsKey("-x");
      if (b)
      {
         try
         {
            Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            b = false;
         }
      }

      return b;
   }

   /**
    * Extract the command-line parameters and initialize the MQ HashTable.
    * @param args
    * @throws IllegalArgumentException
    */
   private void init(String[] args) throws IllegalArgumentException
   {
      int port = 1414;
      if (args.length > 0 && (args.length % 2) == 0)
      {
         for (int i = 0; i < args.length; i += 2)
         {
            params.put(args[i], args[i + 1]);
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }

      if (allParamsPresent())
      {
         qMgrName = (String) params.get("-m");
         inputQName = (String) params.get("-q");
         outputQName = (String) params.get("-o");

         try
         {
            port = Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            port = 1414;
         }

         mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
         mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));
         mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
         mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
         mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));

         // I don't want to see MQ exceptions at the console.
         MQException.log = null;
      }
      else
      {
         throw new IllegalArgumentException();
      }
   }

   /**
    * This method will do the following:
    * 1. Connect 
    * 2. Open input queue, get a request message, close queue 
    * 3. Open output queue, send a reply message, close queue
    * 4. Disconnect.
    */
   private void doIt()
   {
      MQQueueManager qMgr = null;
      
      try
      {
         qMgr = new MQQueueManager(qMgrName, mqht);
         MQTest77.logger("successfully connected to "+ qMgrName);
         
         MQMessage requestMsg = getRequestMsg(qMgr);
         
         if (requestMsg != null)
         {
            ResponseStuff rs = doSomeLogic(requestMsg);
            if (rs != null)
               sendReplyMsg(qMgr, rs);
         }
      }
      catch (MQException e)
      {
         MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
      }
      finally
      {
         try
         {
            if (qMgr != null)
            {
               qMgr.disconnect();
               MQTest77.logger("disconnected from "+ qMgrName);
            }
         }
         catch (MQException e)
         {
            MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
      }
   }

   /**
    * Open the input queue, get a message, close queue.
    * @param qMgr
    * @return requestMsg
    */
   private MQMessage getRequestMsg(MQQueueManager qMgr)
   {
      MQQueue queue = null;
      int openOptions = CMQC.MQOO_INPUT_AS_Q_DEF + CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING;
      MQGetMessageOptions gmo = new MQGetMessageOptions();
      gmo.options = CMQC.MQGMO_PROPERTIES_FORCE_MQRFH2 + CMQC.MQGMO_FAIL_IF_QUIESCING + CMQC.MQGMO_NO_WAIT;
      MQMessage requestMsg = null;
      
      try
      {
         queue = qMgr.accessQueue(inputQName, openOptions);
         MQTest77.logger("successfully opened "+ inputQName);

         requestMsg = new MQMessage();
         requestMsg.messageId = CMQC.MQMI_NONE;
         requestMsg.correlationId = CMQC.MQCI_NONE;

         // get the message on the queue
         queue.get(requestMsg, gmo);
      }
      catch (MQException e)
      {
         MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         
         if ( (e.completionCode == CMQC.MQCC_FAILED) && (e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) )
         {
            MQTest77.logger("No messages on the queue: " + inputQName);
            requestMsg = null;  // no message on queue
         }
      }
      finally
      {
         try
         {
            if (queue != null)
            {
               queue.close();
               MQTest77.logger("closed input: "+ inputQName);
            }
         }
         catch (MQException e)
         {
            MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
      }
      
      return requestMsg;
   }

   /**
    * This is the method where you would normally do business logic stuff.
    * This code will we will take the checksum of the request
    * message and use the value as a seed to the random number generator
    * to that will generate numbers for the next PowerBall lottery!!
    * 
    * @param requestMsg
    */
   private ResponseStuff doSomeLogic(MQMessage requestMsg)
   {
      SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd");
      ResponseStuff rs = new ResponseStuff();
      byte[] msgInBytes;
      
      try
      {
         rs.setRequestMsgId(requestMsg.messageId);
         
         requestMsg.seek(0);  // Important: put the cursor at the beginning of the message.
         MQRFH2 requestRFH2 = new MQRFH2(requestMsg);

         // Save the RFH2 Values
         rs.setRfh2(extractRFH2Values(requestRFH2));
         
         if (CMQC.MQFMT_STRING.equals(requestRFH2.getFormat()))
         {
            String msgStr = requestMsg.readStringOfByteLength(requestMsg.getDataLength());
            msgInBytes = msgStr.getBytes();
         }
         else
         {
            msgInBytes = new byte[requestMsg.getDataLength()];
            requestMsg.readFully(msgInBytes);
         }
         
         /**
          * Now do something with the request message payload.
          * i.e. process msgStr
          * 
          * But we are going to generate PowerBall lottery numbers.
          * 
          */

         /* Apply checksum to the message payload */
         Checksum checksum = new CRC32();
         checksum.update(msgInBytes, 0, msgInBytes.length);

         // get the current checksum value & use it as a seed value.
         Random random = new Random(checksum.getValue());

         StringBuffer sb = new StringBuffer();
         sb.append("For today, ");
         sb.append(date.format(new Date()));
         sb.append(" your Powerball numbers are: ");
         for (int i=0; i < 4; i++)
            sb.append(random.nextInt(69)+", ");
         sb.append(random.nextInt(69)+" ");
         sb.append("and your power ball is ");
         sb.append(random.nextInt(26));
         
         rs.setResponseText(sb.toString());
      }
      catch (IOException e)
      {
         MQTest77.logger("IOException:" +e.getLocalizedMessage());
      }
      catch (MQDataException e)
      {
         MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
      }
      
      return rs;
   }

   /**
    * Extract the MQRFH2 values we will need.
    * @param requestRFH2
    * @return rfh2
    */
   private MQRFH2 extractRFH2Values(MQRFH2 requestRFH2)
   {
      MQRFH2 replyRFH2 = null;
      
      try
      {
         // Set the RFH2 Values
         replyRFH2 = new MQRFH2();
         replyRFH2.setEncoding(requestRFH2.getEncoding());
         replyRFH2.setCodedCharSetId(requestRFH2.getCodedCharSetId());
         replyRFH2.setFormat(requestRFH2.getFormat());
         replyRFH2.setFlags(requestRFH2.getFlags());
         replyRFH2.setNameValueCCSID(requestRFH2.getNameValueCCSID());

         String[] folders = requestRFH2.getFolderStrings();
         for (int i=0; i < folders.length; i++)
         {
            if ( (folders[i].startsWith("<jms>")) && (folders[i].contains("<Dst>")) && (folders[i].contains("</Dst>")) )
            {
               int prefix = folders[i].indexOf("<Dst>");
               int suffix = folders[i].indexOf("</Dst>");
               // Set the destination to the output queue name.
               folders[i] = folders[i].substring(0, prefix) + "<Dst>queue:///"+outputQName+"</Dst>" + folders[i].substring(suffix+6);
               break;
            }
         }
         replyRFH2.setFolderStrings(folders);
      }
      catch (IOException e)
      {
         MQTest77.logger("IOException:" +e.getLocalizedMessage());
      }
      
      return replyRFH2;
   }


   /**
    * Open output queue, write a message, close queue.
    * @param qMgr
    * @param requestMsg
    */
   private void sendReplyMsg(MQQueueManager qMgr, ResponseStuff rs)
   {
      MQQueue queue = null;
      int openOptions = CMQC.MQOO_OUTPUT + CMQC.MQOO_FAIL_IF_QUIESCING;
      MQPutMessageOptions pmo = new MQPutMessageOptions();

      try
      {
         queue = qMgr.accessQueue(outputQName, openOptions);
         MQTest77.logger("successfully opened "+ outputQName);

         MQMessage replymsg = new MQMessage();

         // Set the RFH2 Values
         MQRFH2 replyRFH2 = new MQRFH2();
         replyRFH2.setEncoding(rs.getRfh2().getEncoding());
         replyRFH2.setCodedCharSetId(rs.getRfh2().getCodedCharSetId());
         replyRFH2.setFormat(rs.getRfh2().getFormat());
         replyRFH2.setFlags(rs.getRfh2().getFlags());
         replyRFH2.setNameValueCCSID(rs.getRfh2().getNameValueCCSID());
         replyRFH2.setFolderStrings(rs.getRfh2().getFolderStrings());
         
         // Set the MQRFH2 structure to the message
         replyRFH2.write(replymsg);

         // Write message data
         replymsg.writeString(rs.getResponseText());

         // Set MQMD values
         replymsg.messageId = CMQC.MQMI_NONE;
         /* set the reply's Correl Id to be the request message's Msg id */  
         replymsg.correlationId = rs.getRequestMsgId();
         replymsg.messageType = CMQC.MQMT_DATAGRAM;
         
         // IMPORTANT: Set the format to MQRFH2 aka JMS Message.
         replymsg.format = CMQC.MQFMT_RF_HEADER_2;

         // put the message on the queue
         queue.put(replymsg, pmo);
         MQTest77.logger("Message Data>>>" + rs.getResponseText());
      }
      catch (MQException e)
      {
         MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
      }
      catch (IOException e)
      {
         MQTest77.logger("IOException:" +e.getLocalizedMessage());
      }
      finally
      {
         try
         {
            if (queue != null)
            {
               queue.close();
               MQTest77.logger("closed output: "+ outputQName);
            }
         }
         catch (MQException e)
         {
            MQTest77.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
      }
   }

   /**
    * A simple logger method
    * @param data
    */
   public static void logger(String data)
   {
      String className = Thread.currentThread().getStackTrace()[2].getClassName();

      // Remove the package info.
      if ( (className != null) && (className.lastIndexOf('.') != -1) )
         className = className.substring(className.lastIndexOf('.')+1);

      System.out.println(LOGGER_TIMESTAMP.format(new Date())+" "+className+": "+Thread.currentThread().getStackTrace()[2].getMethodName()+": "+data);
   }

   /**
    * main line
    * @param args
    */
   public static void main(String[] args)
   {
      MQTest77 write = new MQTest77();

      try
      {
         write.init(args);
         write.doIt();
      }
      catch (IllegalArgumentException e)
      {
         MQTest77.logger("Usage: java MQTest77 -m QueueManagerName -h host -p port -c channel -q InputQueueName -o OutputQueueName-u UserID -x Password");
         System.exit(1);
      }

      System.exit(0);
   }
   
   /**
    * This class will hold the information to be used in the reply message.
    */
   class ResponseStuff
   {
      private MQRFH2 rfh2;
      private String responseText;
      private byte[] requestMsgId;

      /**
       * The constructor
       */
      public ResponseStuff()
      {
         super();
         rfh2 = new MQRFH2();
      }

      public MQRFH2 getRfh2()
      {
         return rfh2;
      }

      public void setRfh2(MQRFH2 rfh2)
      {
         this.rfh2 = rfh2;
      }

      public String getResponseText()
      {
         return responseText;
      }

      public void setResponseText(String responseText)
      {
         this.responseText = responseText;
      }

      public byte[] getRequestMsgId()
      {
         return requestMsgId;
      }

      public void setRequestMsgId(byte[] requestMsgId)
      {
         this.requestMsgId = requestMsgId;
      }

   }
}

Regards,
Roger Lacroix
Capitalware Inc.

HPE NonStop, IBM i (OS/400), IBM MQ, IBM MQ Appliance, Java, JMS, Linux, macOS (Mac OS X), Open Source, Programming, Raspberry Pi, Unix, Windows, z/OS Comments Off on Request & Reply JMS/MQRFH2 Messaging Scenario

IBM announces WebSphere MQ V5.3.1 Fix Pack 16 for HPE NonStop

IBM has just released Fix Pack 5.3.1.16 for WebSphere MQ for HPE NonStop:
https://www.ibm.com/support/docview.wss?uid=swg1IT29752

Regards,
Roger Lacroix
Capitalware Inc.

Fix Packs for MQ, HPE NonStop, IBM MQ Comments Off on IBM announces WebSphere MQ V5.3.1 Fix Pack 16 for HPE NonStop

Capitalware Product Advisory

A bug was discovered in Capitalware’s framework subroutine for removing trailing blanks (spaces) from a variable. If the contents of the variable contained only blanks then the code miscalculated the length by 1. This bug affects all commercial and “Licensed as Free” products.

    Commercial Products for distributed platforms affected:

  • MQ Auditor
  • MQ Authenticate User Security Exit
  • MQ Channel Connection Inspector
  • MQ Channel Encryption
  • MQ Channel Throttler
  • MQ Message Encryption
  • MQ Message Replication
  • MQ Standard Security Exit
    Commercial Products for z/OS affected:

  • MQ Authenticate User Security Exit for z/OS
  • MQ Channel Connection Inspector for z/OS
  • MQ Channel Encryption for z/OS
  • MQ Standard Security Exit for z/OS

To receive updates to the commercial products, please send an email to support@capitalware.com

    Licensed as Free Products affected:

  • MQ Channel Auto Creation Manager
  • MQ Set UserID
  • Client-side Security Exit for Depository Trust Clearing Corporation
  • MQ Channel Auto Creation Manager for z/OS
  • MQ Set UserID for z/OS
  • Client-side Security Exit for Depository Trust Clearing Corporation for z/OS

The updates for the “Licensed as Free” products have been posted to Capitalware’s web site, so you can download them immediately.

Regards,
Roger Lacroix
Capitalware Inc.

Capitalware, IBM i (OS/400), Linux, MQ Auditor, MQ Authenticate User Security Exit, MQ Channel Connection Inspector, MQ Channel Encryption, MQ Channel Throttler, MQ Enterprise Security Suite, MQ Message Encryption, MQ Message Replication, MQ Standard Security Exit, Unix, Windows, z/OS Comments Off on Capitalware Product Advisory

IBM MQ Fix Pack 8.0.0.14 Released

IBM has just released Fix Pack 8.0.0.14 for IBM MQ
https://www.ibm.com/support/pages/node/1282120

Regards,
Roger Lacroix
Capitalware Inc.

Fix Packs for MQ, IBM i (OS/400), IBM MQ, Linux, Unix, Windows Comments Off on IBM MQ Fix Pack 8.0.0.14 Released

SQLite v3.31.0 Released

D. Richard Hipp has just released SQLite v3.31.0.
http://www.sqlite.org/news.html

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.

Regards,
Roger Lacroix
Capitalware Inc.

C, Database, IBM i (OS/400), Linux, macOS (Mac OS X), Open Source, Programming, Unix, Windows, z/OS Comments Off on SQLite v3.31.0 Released

IBM MQ and C# .NET Compatibility

Today, I went to build (compile) and run a C# .NET/MQ sample that I have which worked perfectly before and I got the following error when I ran it:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'amqmdnet, Version=9.1.3.0, Culture=neutral, PublicKeyToken=dd3cb1c9aae9ec97' or one of its dependencies. The system cannot find the file specified.
File name: 'amqmdnet, Version=9.1.3.0, Culture=neutral, PublicKeyToken=dd3cb1c9aae9ec97'
   at MQTest71.MQTest71.Main(String[] args)

I compiled it again. No errors and it successfully generated the executable. Weird. When I ran it, I got the above error message.

I searched the internet and didn’t find a specific hit but found several pages that talked about creating a .NET Framework 4.0 application that references a .NET Standard 2.0 library.

This got me thinking about the C# compiler I was using versus the .NET runtime that was being used. The batch file to do the build was using the “csc.exe” (compiler) from .NET v2.0.

I did a quick of my C: drive and found that I had 3 .NET frameworks installed: v2.0, v3.5. and v4.6.1.

Note: Under “Programs and Features“, it shows I have “Microsoft .NET Framework 4.6.1 SDK” installed. The path to the compiler is C:\Windows\Microsoft.NET\Framework\v4.0.30319\. If you want to read about Microsoft’s .NET odd naming standards, you can read the article here. I do not have any entries for .NET v2.0 or .NET v3.5 (more odd behavior by Microsoft).

So, I updated my build batch file to use the compiler from .NET framework v4.6.1 and compiled my simple C# .NET/MQ program. It compiled fine and of course, it ran perfectly fine.

I know I used the .NET framework v2.0 with MQ v8.0 and it worked fine, so I decided to check out IBM MQ’s system requirements for software compilers. Here’s what I found for IBM MQ and the officially supported releases of .NET:

  • IBM MQ 8.0 supports .NET 3.5, 4.0 & 4.5
  • IBM MQ 9.0 supports .NET 3.5, 4.0, 4.5 & 4.6
  • IBM MQ 9.1 supports .NET 4.5.1, 4.6 & 4.7

Regards,
Roger Lacroix
Capitalware Inc.

.NET, C#, Programming, Windows Comments Off on IBM MQ and C# .NET Compatibility

JMS/MQRFH2 Message Properties in “other” Folder

On StackOverflow, someone asked about having an “other” folder (not “usr”) with an MQRFH2 (aka JMS) message.

That day, I played around with a MQ/Java program that created various folders in an MQRFH2 message.
i.e.

MQMessage sendmsg = new MQMessage();
MQRFH2 rfh2 = new MQRFH2();
rfh2.setEncoding(CMQC.MQENC_NATIVE);
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT);
rfh2.setFormat(CMQC.MQFMT_STRING);
rfh2.setFlags(0);
rfh2.setNameValueCCSID(1208);
// type of JMS message
rfh2.setFieldValue("mcd", "Msd", "jms_text");
rfh2.setFieldValue("jms", "Dst", "queue:///"+outputQName);
// set named properties in the "usr" folder
rfh2.setFieldValue("usr", "SomeNum", 123);
rfh2.setFieldValue("usr", "SomeText", "TEST");
// set named properties in the "other" folder
rfh2.setFieldValue("other", "thingA", 789);
rfh2.setFieldValue("other", "thingB", "XYZ");
// Set the MQRFH2 structure to the message
rfh2.write(sendmsg);
sendmsg.writeString("This is a test message.");
// IMPORTANT: Set the format to MQRFH2 aka JMS Message.
sendmsg.format = CMQC.MQFMT_RF_HEADER_2;
// put the message on the queue
queue.put(sendmsg, pmo);

When I ran a MQ/JMS program to retrieve the messages, the MQ/JMS programs simply ignore all folders outside of ‘mcd’, ‘jms’ and ‘usr’.

QueueReceiver receiver = session.createReceiver(myQ);
Message inMessage = receiver.receive();
String thing = inMessage.getStringProperty("other.thingB");
System.out.println("   thing="+thing);

Enumeration<String> props = inMessage.getPropertyNames();
if (props != null)
{
   while (props.hasMoreElements())
   {
      String propName = props.nextElement();
      Object o = inMessage.getObjectProperty(propName);
      System.out.println("   Name="+propName+" : Value="+o);
   }
}

Any named properties in the “other” folder are simply ignored by the JMS framework.

If you are wondering about C programs, yes, they can get access named properties in the “other” folder. When using the MQINQMP API call, there is no parameter for the folder name, so you code it as a qualifier to the name keyword. i.e. “other.thingB”

MQCHARV  inqname = {(MQPTR)(char*)"other.thingB", 0, 0, 12, MQCCSI_APPL};
impo.Options = MQIMPO_INQ_NEXT;
impo.ReturnedName.VSPtr = name;
impo.ReturnedName.VSBufSize = sizeof(name)-1;
type = MQTYPE_STRING;
MQINQMP(Hcon, Hmsg, &impo, &inqname, &pd, &type, sizeof(value)-1, value, &datalen, &CompCode, &Reason );
printf("property name <%s> value <%s>\n", name, value);

So, if you want to use a folder called “other”, that is fine, so long as you don’t want the information to be used by a JMS/MQ program, otherwise, you need to put the name/value properties in the ‘usr’ folder.

Regards,
Roger Lacroix
Capitalware Inc.

C, IBM i (OS/400), IBM MQ, Java, JMS, Linux, macOS (Mac OS X), Programming, Unix, Windows, z/OS Comments Off on JMS/MQRFH2 Message Properties in “other” Folder

Merry Christmas and Happy New Year

I would like to wish everyone a Merry Christmas, Happy Hanukkah, Happy Kwanzaa, etc… and a Happy New Year. 🙂

Regards,
Roger Lacroix
Capitalware Inc.

General 1 Comment

Windows Print Screen

Ok. Here’s something not related to MQ or programming. 🙂

Everyday, someone sends Capitalware a support request with an image or two. Its not a problem. I review what they asking and send back a reply.

Most of the images I receive are some sort of cropped image of the whole desktop. Sometimes the image is tightly cropped to whatever they are sending and sometimes I’m getting too much information about their desktop.

A far better way of sending Capitalware a screen shot of information is to use one of the following 2 options:

(1) Bring the window to the foreground (so that it is active) then press ALT-PrtScn. i.e. Hold the ALT key then press the PrtScn (Print Screen) key. Windows will capture an image of ONLY the active window and place it in the clipboard and then the user can paste it into an email.

(2) Use the Snipping Tool that has been available since Windows Vista. Start it, select the Mode (i.e. Rectangular Snip), click New button and select whatever you want then paste it into the email.

Note: None of the images are shared with anyone or other companies but it is far, far better for people to only send Capitalware information that I need to see.

Regards,
Roger Lacroix
Capitalware Inc.

Capitalware, Windows Comments Off on Windows Print Screen

MQ Internals Explained (a little bit)

IBM likes to market IBM MQ (aka WebSphere MQ, MQSeries) as a simple and complete solution for business’s messaging needs. Going with the KISS approach is wise (very wise in some cases).

IBM talks about the 2 different messaging models that IBM MQ supports: Point-to-Point (P2P) and Publish/Subscribe (Pub/Sub).

    IBM will:

  • show you how to put messages to local/alias/cluster/remote queues (P2P) or get messages from local/alias/cluster queues (P2P).
  • show you how to publish messages to a topic string or object (Pub/Sub) or subscribe to a subscription (or topic) to retrieve messages from a topic string or object (Pub/Sub).
  • show you how to create an alias queue that can point to (1) a local queue (P2P) or (2) a topic (Pub/Sub) and if you use a topic, how to cross messages from the P2P model to the Pub/Sub model.
  • show you how to create a subscription that can point to (1) a local queue (P2P) or (2) a topic (Pub/Sub) and if you use a local or alias queue, how to cross messages from the Pub/Sub model to the P2P model.

IBM likes to show the world that IBM MQ use of Point-to-Point and Publish/Subscribe is a single messaging model. While IBM markets IBM MQ as a single messaging model is fine (aka the KISS approach), it sometimes makes my life a little difficult when explaining either MQ Message Encryption or MQ Auditor to customers (although, less so with MQ Auditor, because by default, it collects information from both messaging models).

Here’s an example: A customer recently sent me a picture of a setup they were trying to implement with MQ Message Encryption (MQME) and they were confused why MQME did not do its job of encrypting messages when the messages were put/published at different points in the setup.

Here’s the picture of their setup:

For those who prefer MQSC definitions, here they are:

DEFINE QALIAS('TEST_ALIAS') TARGET('TEST_TOPIC') TARGTYPE(TOPIC)
DEFINE QREMOTE('TEST_QUEUE_REM') RQMNAME('QMGR2') RNAME('TEST_QUEUE') XMITQ('QMGR2')
DEFINE QLOCAL('TEST_QUEUE_LOC')
DEFINE TOPIC('TEST_TOPIC') TOPICSTR('MQME/TEST')
DEFINE SUB('TEST_SUB_1') TOPICSTR('') TOPICOBJ('TEST_TOPIC') DEST('TEST_QUEUE_REM')
DEFINE SUB('TEST_SUB_2') TOPICSTR('') TOPICOBJ('TEST_TOPIC') DEST('TEST_QUEUE_LOC')

When they put a message to the alias queue, everything was fine but when they published a message to the topic ‘MQME/TEST’ then the message was not encrypted.

In the user’s MQME IniFile, they only had set the protected queue(s) of ‘TEST*’. They did NOT have any protected topic definitions.

There are many things I need to explain that goes on under the covers with MQ. I will do my best to explain it in a logical order but I know that I’m about to confuse many people.

Things to remember:

(1) When messages flow through P2P model/environment, the message can be a plain message, JMS message (aka MQRFH2), CICS message, IMS message, SAP message, etc.

Layout for 5 example messages for P2P:

{message payload}
{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}
{CICS header}{message payload}
{IMS header}{message payload}
{SAP header}{message payload}

(2) When messages flow through Pub/Sub model/environment, the message MUST be a JMS message (aka MQRFH2) formatted message. Now a JMS message can contain a CICS message, IMS message, SAP message, etc.

Layout for 4 example messages for Pub/Sub:

{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}
{RFH2 header}{mcd folder}{jms folder}{usr folder}{CICS header}{message payload}
{RFH2 header}{mcd folder}{jms folder}{usr folder}{IMS header}{message payload}
{RFH2 header}{mcd folder}{jms folder}{usr folder}{SAP header}{message payload}

Note: The user can change the queue’s property attribute (PROPCTL) or subscription’s property attribute (PSPROP) to ‘NONE’, so that MQ removes the message properties (aka named properties) and folders when the message is retrieved by the application.

Item #1:
When an application opens an alias queue, internally that object type is called MQOT_Q. Hence, MQ is operating in the P2P model. Since, it is the P2P model, MQME will check its protect queue definitions for the a match. If MQME finds a match then all messages put to or retrieved from that object handle (aka opened queue) will be encrypted or decrypted (assuming permissions are correct).

When the user ran an application to publish a message to topic ‘MQME/TEST’, the topic was opened and the object type was MQOT_TOPIC. Since, it is the Pub/Sub model, MQME will check its protect topic definitions for the a match. In this particular case, MQME did not find a match, so it will not encrypt the messages or decrypt the messages for subscribers.

Now if the user adds a protect topic definition to the MQME IniFile with something like ‘MQME/TEST’ or ‘MQME/*’ or ‘MQME/TEST*’ then MQME would find a match and encrypt or decrypt messages of that particular topic.

Here’s the analogy that I like to use with customers, think of IBM MQ as a brain (human brain if you will). Each person has a single brain. IBM MQ provides a single messaging infrastructure. But if you look closely at the brain, you will see that it is made up of 2 hemispheres and if you look closely, you will see that IBM MQ is made up of 2 different messaging models: Point-to-Point and Publish/Subscribe.

So, how an application opens a queue or topic will dictate which side of the brain (aka messaging system) MQ will use to handle the getting or putting of messages. And if companies have a configuration where messages flow back and forth between the 2 messaging systems then the users of MQME need to beware of the point of contact with the MQ (aka the brain).

Item #2:
Did you know that when a message hops between P2P and Pub/Sub that the message actually changes! Also, for those of you that are using MQ’s Pub/Sub for message replication, did you know that not all MQMD fields of the original message are replicated to the copied messages!

Example:

Using the above customer setup, if you start MQ Explorer and put a test message to the alias queue ‘TEST_ALIAS’ then the following is what happens to the message:

– Putting a plain message to an alias queue

{message payload}

– When MQ transfers the message to a topic object or subscription then the message becomes

{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}

– When the message is put to the XMITQ queue it looks like

{XMIT header}{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}

– When it is put to the local queue of the local queue manager, it is still in the format:

{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}

– When it is put to the local queue of the remote queue manager, it is still in the format:

{RFH2 header}{mcd folder}{jms folder}{usr folder}{message payload}

Note: For those newbies out there, MQRFH2 is the internal name for a JMS message. Also, yes, I know on the subscription, the user can change the Property attribute (PSPROP) to ‘NONE’, so that MQ removes the message properties (aka named properties) which in theory turns the message back to a regular message.

Users of MQ should really be aware of what goes on under the covers with MQ, so that they don’t blame MQ when they don’t get the results they want.

Also, there are far simpler solutions for handling message replication. i.e. MQ Message Replication

If you want, you can sub-title this blog posting as ‘your brain on MQ!’ 🙂

Regards,
Roger Lacroix
Capitalware Inc.

.NET, Assembler, C, C#, C++, HPE NonStop, IBM i (OS/400), IBM MQ, Java, JMS, Linux, macOS (Mac OS X), MQ Auditor, MQ Message Encryption, Programming, Unix, Windows, z/OS 2 Comments