In the last few weeks, I’ve had two different customers asking about the default behaviour of the IBM MQ classes for Java method MQMessage.writeString(String). I thought I’d put together a short blog post that provides the answer.

Suppose I have an IBM MQ classes for Java application that contains the following code:

try {
  // Connect to the queue manager myQueueManager.
  MQQueueManager qmgr = new MQQueueManager("myQueueManager");
  System.out.println("Connected to queue manager");
  // Open queue1 on the queue manager
  MQQueue outputQueue = qmgr.accessQueue("queue1", MQC.MQOO_OUTPUT);
  System.out.println("queue1 opened");

  // Construct a new MQMessage.
  MQMessage msg = new MQMessage();
  // Write some String data into the message
  msg.writeString("Hello World");	
  System.out.println("MQMessage created");
  // Send the message.
  MQPutMessageOptions pmo = new MQPutMessageOptions();
  System.out.println("About to put message to queue1");
  outputQueue.put(msg, pmo);
  System.out.println("Message put to queue1 successfully");

  // Shutdown
  System.out.println("Disconnected from the queue manager");
} catch (Exception e) {
  System.out.println("Exception occurred: " + e.toString());

The call to MQMessage.writeString(String) on line 12 will take the String “Hello World” and encode it into a byte sequence using the coded character set identifier (CCSID) specified by the MQMessage field characterSet.

If this field is set to the default value of CMQC.MQCCSI_Q_MGR, then the IBM MQ classes for Java will look at the platform that the application is running on to determine which CCSID to use to encode the string:

  • If the IBM MQ classes for Java application is running on z/OS, then the IBM MQ classes for Java will encode the string data using CCSID 500.
  • For all other platforms, the IBM MQ classes for Java will use CCSID 819 to encode the string data.

This behaviour is the same, regardless of whether the application is connecting to the queue manager using either the BINDINGS or CLIENT transport.

At the time of writing, this is not currently documented in the IBM MQ sections of IBM Knowledge Center. It should be added soon though!

Leave a Reply