Exchanging a formatted record with a non-JMS application
Follow the steps suggested in this task to design and build a data conversion exit, and a JMS client application that can exchange messages with a non-JMS application using JMSBytesMessage. The exchange of a formatted message with a non-JMS application can take place with or without calling a data conversion exit.
Before you begin
About this task
A JMS client is easier to write if it is not involved in the details of formatting JMS messages exchanged with other JMS clients. As long as the message type is JMSTextMessage, JMSMapMessage, JMSStreamMessage, or JMSObjectMessage, IBM® MQ looks after the details of formatting the message. IBM MQ deals with differences in code pages and numeric encoding on different platforms.
You can use these message types to exchange messages with non-JMS applications. To do so, you must understand how these messages are constructed by IBM MQ classes for JMS. You might be able to modify the non-JMS application to interpret the messages; see Mapping JMS messages onto IBM MQ messages.
An advantage of using one of these message types is the JMS client programming does not depend on the type of application that it is exchanging messages with. A disadvantage is that it might require a modification to another program, and you might not be able to change the other program.
An alternative approach is to write a JMS client application that can deal with existing message formats. Often existing messages are fixed format and contain a mixture of unformatted data, text, and numbers. Use the steps in this task, and the example JMS client in Writing classes to encapsulate a record layout in a JMSBytesMessage, as a starting point for building a JMS client that can exchange formatted records with non-JMS applications.
Procedure
Examples
struct RECORD { MQCHAR StrucID[4];
MQLONG Version;
MQLONG StructLength;
MQLONG Encoding;
MQLONG CodeCharSetId;
MQCHAR Format[8];
MQLONG Flags;
MQCHAR RecordData[32];
};
- Declare the RECORD.h data structure
struct tagRECORD { MQCHAR4 StrucId; MQLONG Version; MQLONG StrucLength; MQLONG Encoding; MQLONG CCSID; MQCHAR8 Format; MQLONG Flags; MQCHAR32 RecordData; }; typedef struct tagRECORD RECORD; typedef RECORD MQPOINTER PRECORD; RECORD record; PRECORD pRecord = &(record);
- Modify the MQGET call to use RECORD,
- Before modification:
MQGET(Hcon, /* connection handle */ Hobj, /* object handle */ &md, /* message descriptor */ &gmo, /* get message options */ buflen, /* buffer length */ buffer, /* message buffer */ &messlen, /* message length */ &CompCode, /* completion code */ &Reason); /* reason code */
- After modification:
MQGET(Hcon, /* connection handle */ Hobj, /* object handle */ &md, /* message descriptor */ &gmo, /* get message options */ sizeof(RECORD), /* buffer length */ pRecord, /* message buffer */ &messlen, /* message length */ &CompCode, /* completion code */ &Reason); /* reason code */
- Before modification:
- Change the print statement,
- From:
buffer[messlen] = '\0'; /* add terminator */ printf("message <%s>\n", buffer);
- To:
/* buffer[messlen] = '\0'; add terminator */ printf("ccsid <%d>, flags <%d>, message <%32.32s>\n \0", md.CodedCharSetId, record.Flags, record.RecordData);
- From: