Working with MQSeries Message Descriptor Format

Format is a message descriptor attribute. Messages of a particular Format conform to a specific structure which depends on the Format type. For example, CICS, IMS, MQRFH2, and so on. The structure for each built-in MQSeries Format is different and is defined by MQSeries. For more information on MQSeries Formats, see the online MQSeries documentation at the following URL:

http://www.ibm.com

Using the MQSeries control you can send messages that correspond to built-in MQSeries formats and user-defined formats. This can only be done using the putMessageAsBytes function.

To send a message that conforms to an MQSeries Format, you must add Java code to the process JPD file. This is shown in the following examples.

Example: Sending a message that conforms to the CICS Format (using the putMessage function)

  1. Declare a variable, for example, putin, in your application process JPD file, as follows:
  2. public com.bea.wli.control.mqmdHeaders.MQMDHeadersDocument putin; 
    

    This variable represents the input MQMDHeaders document XMLBean variable for the putMessage function.

  3. Drag and drop the Perform node from the Palette into the business process, just below the Client Request node.
  4. Open the Perform node in the Source View and add the following code.
  5. public void perform() throws Exception
    {
    putin.getMQMDHeaders().setFormat(MQC.MQFMT_CICS);
    bytmsg = getCICSHeader();
    }
    public byte[] getCICSHeader() throws Exception    {
    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
    DataOutputStream ostream = new DataOutputStream (bstream); ostream.writeChars("CIH "); // Struct id 
    
    ostream.writeInt(1);      // Version 
    ostream.writeInt(164);    // StrucLength
    ostream.writeInt(273);    // Encoding 
    ostream.writeInt(819);    // CodedCharSetId
    ostream.writeChars("        "); // Format
    ostream.writeInt(0);      //Flags
    ostream.writeInt(0);      //ReturnCode
    ostream.writeInt(0);      //CompCode
    ostream.writeInt(0);      //Reason
    ostream.writeInt(273);    //UOWControl
    ostream.writeInt(-2);     //GetWaitInterval
    ostream.writeInt(1);      //LinkType
    ostream.writeInt(-1);     //OutputDataLength
    ostream.writeInt(0);      //FacilityKeepTime
    ostream.writeInt(0);      //ADSDescriptor
    ostream.writeInt(0);      //ConversationalTask
    ostream.writeInt(0);      //TaskEndStatus
    ostream.writeBytes("\0\0\0\0\0\0\0\0");   //Facility
    ostream.writeChars("    ");   //Function
    ostream.writeChars("    ");   //AbendCode
    ostream.writeChars("        ");   //Authenticator
    ostream.writeChars("        ");   //Reserved1
    ostream.writeChars("        ");   //ReplyToFormat
    ostream.writeChars("    ");  //RemoteSysId
    ostream.writeChars("    ");  //RemoteTransId
    ostream.writeChars("    ");  //TransactionId
    ostream.writeChars("    ");  //FacilityLike
    ostream.writeChars("    ");  //AttentionId
    ostream.writeChars("    ");  //StartCode
    ostream.writeChars("    ");  //CancelCode
    ostream.writeChars("    ");  //NextTransactionId
    ostream.writeChars("        "); //Reserved2
    ostream.writeChars("        ");  //Reserved3
    ostream.writeChars("HelloWorld");
    ostream.flush();
    byte[] bArr = bstream.toByteArray();
    return bArr;
    } 
    

    This code sets the Format element in the input MQMD Headers document of the putMessage function to MQC.MQFMT_CICS, represented by the String "MQCICS".

    The getCICSHeader function writes the fields present in the CICS header to a byte array output stream and returns an array of bytes. The field values given in this example can be modified as required. The actual message can be appended to the end of this byte array and can be Put into the MQSeries queue. The byte array can be provided as the first parameter to the putMessageAsBytes function, which is added to the process JPD file after the Perform node. For more information on the putMessage function, see Sending and Receiving Messages.

Example: Sending a message that conforms to the IMS Format (using the putMessage function)

  1. Declare a variable, for example, putin, in the application process JPD file, as follows:
  2. public com.bea.wli.control.mqmdHeaders.MQMDHeadersDocument putin; 
    

    This variable represents the input MQMDHeaders document XMLBean variable for the putMessage function.

  3. Drag and drop the Perform node from the Palette into the business process, just below the Client Request node.
  4. Open the Perform node in the Source View and add the following code.
  5. public void perform() throws Exception
    {
    putin.getMQMDHeaders().setFormat(MQC.MQFMT_IMS);
    bytmsg = getIMSHeader();
    }
    public byte[] getIMSHeader() throws Exception    {
    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
    DataOutputStream ostream = new DataOutputStream (bstream); 
    
    ostream.writeBytes("IIH "); // Struct id
    ostream.writeInt(1);      // Version 
    ostream.writeInt(84);     // Length
    ostream.writeInt(0);      // Encoding
    ostream.writeInt(0);      // CodedCharacterSet
    ostream.writeBytes("        "); // Format (8 characters)
    ostream.writeInt(0);      // Flags
    ostream.writeBytes("        "); // LTermOverride
    ostream.writeBytes("        "); // MFSMapName
    ostream.writeBytes("        "); // ReplyToFormat
    ostream.writeBytes("        "); // Authenticator
    ostream.writeBytes("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");  // TransInstanceId
    ostream.writeBytes(" ");  //Transtate
    ostream.writeBytes("1");  // CommitMode
    ostream.writeBytes("F");  // Security Scope
    ostream.writeBytes(" ");  // Resrved 
    ostream.writeChars("HelloWorld");
    ostream.flush();
    byte[] bArr = bstream.toByteArray();
    return bArr;
    } 
    

    The previous lines of code set the Format element in the input MQMD Headers document of the putMessage function to MQC.MQFMT_IMS, represented by the String "MQIMS ".

    The getIMSHeader function writes the fields present in the IMS header structure to a byte array output stream and returns an array of bytes. The values of the fields given in this example can be modified as required. The actual message can be appended to the end of the byte array and can be Put into the MQSeries queue. The byte array can be provided as the first parameter to the putMessageAsBytes function, which is added to the process JPD file after the Perform node. For more information on the putMessage function, see Sending and Receiving Messages.

Example: Sending a message that conforms to the MQRFH2 Format (using the putMessage function)

  1. Declare a variable, for example, putin, in the JPD file of your process project in the application, as follows:
  2. public com.bea.wli.control.mqmdHeaders.MQMDHeadersDocument putin; 
    

    This variable represents the input MQMDHeaders document XMLBean variable for the putMessage function.

  3. Drag and drop the Perform node from the Palette into the business process, just below the Client Request node.
  4. Open the Perform node in the Source View and add the following code.
  5. public void perform() throws Exception
    {
    putin.getMQMDHeaders().setFormat(MQC.MQFMT_RF_HEADER_2);
    bytmsg = getMQRFH2Header();
    }
    public byte[] getMQRFH2Header() throws Exception    { ByteArrayOutputStream bstream = new ByteArrayOutputStream(); DataOutputStream ostream = new DataOutputStream (bstream);
    String strVariableData = "<mcd><Msd>jms_text</Msd></mcd><jms><Dst>someplace</Dst></jms>";
    int iStrucLength = MQC.MQRFH_STRUC_LENGTH_FIXED_2 + strVariableData.getBytes().length;
    			while(iStrucLength % 4 != 0)
    {
    strVariableData  = strVariableData  + " ";
    iStrucLength = MQC.MQRFH_STRUC_LENGTH_FIXED_2 + strVariableData.getBytes().length;
    }
    ostream.writeChars(MQC.MQRFH_STRUC_ID);//StrucID ostream.writeInt(MQC.MQRFH_VERSION_2);//Version ostream.writeInt(iStrucLength );//StrucLength ostream.writeInt(273);//Encoding ostream.writeInt(1208);//CodedCharSetID ostream.writeChars(MQSTR);//Format ostream.writeInt(MQC.MQRFH_NO_FLAGS);//Flags ostream.writeInt(1208);//NameValueCCSID ostream.writeInt(strVariableData.getBytes().length);//NameValueLength ostream.writeChars(strVariableData ); //NameValueData ostream.writeChars("HelloWorld");
    ostream.flush();
    byte[] bArr = bstream.toByteArray();
    return bArr;
    } 
    

    The previous code sets the Format element in the input MQMD Headers document of the putMessage function to MQC.MQFMT_RF_HEADER_2,represented by the String "MQHRF2 ".

    The getMQRFH2Header function writes the fields present in the MQRFH2 header structure to a byte array output stream and returns an array of bytes. The values of the fields given in this example can be modified as required. The actual message can be appended to the end of the byte array and can be Put into the MQSeries queue. The byte array can be provided as the first parameter to the putMessageAsBytes function, which is added to the process JPD file after the Perform node. For more information on the putMessage function, see Sending and Receiving Messages.

Previous Document Next Document