In an environment where many applications/devices run on different OS/infrastructure and communicate through messaging using WebSphere MQ as middleware, there is always some chance of messages getting lost due to network problems or due to application crashes.
We must handle those exceptions in our application to make sure that we do not lose any message.
Here are some practical examples of problems and their solutions that I have faced while working on some big Financial Applications.
If an application throws some type of exception (Business logic failure, DB failure) after reading messages from Queues, how are you going to handle the message that you already read?
How to handle a proper asynchronous request/reply communication, to make sure that we do not misunderstand a reply for a specific request?
What if WebSphere Queue Manager crashed out after you put messages on a queue?
Syncpoint coordination is the process by which units of work are either committed or backed out with data integrity.
You must write your application to handle Synch Point Commit and Back out so that if anything fails, you would be able to easily back out the message.
A correlation ID is usually put in the header of a message. The ID is not part of the command or data the caller is trying to communicate to the receiver.
The receiver saves the ID from the request and adds it to the reply for the caller's benefit. Since the message body is the content being transmitted between the two systems, and the ID is not a part of that, the ID is added to the header.
In the request message, the ID can be stored as a correlation ID property or simply a message ID property. When used as a correlation ID, this can cause confusion about which message is the request and which is the reply. If a request has a message ID but no correlation ID, then a reply has a correlation ID that is the same as the request's message ID.
You must write your application to read write messages using correlation id in an asynchronous request/reply environment.
Using the Code
Given below is the C++ code for reading/writing messages from/to queues using Synch Point Commit, Back Out and Correlation ID...
ImqQueue request_queue; ImqMessage msg ; ImqPutMessageOptions pmo;
request_queue.put( msg, pmo );
ImqBinary pID( msg.messageId() );
pID.copyOut( &corrID, 128 );
ImqQueue reply_queue; ImqMessage msg ; ImqGetMessageOptions GMO;
ImqQueue request_queue; ImqQueue reply_queue; ImqGetMessageOptions GMO;
else if ()