user3714601
user3714601

Reputation: 1271

Client Receive Exit with IBM Websphere MQ JMS

I'm trying to implement receive exit in java as proposed here: http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.0.1/com.ibm.mq.csqzaw.doc/jm11171_.htm

  // This method implements the receive exit interface
  public ByteBuffer channelReceiveExit(MQCXP channelExitParms,
                                   MQCD channelDefinition,
                                   ByteBuffer agentBuffer)
 {
  // Complete the body of the receive exit here
 }

I see that exit method is called, and following documentation I expect agentBuffer to contain data of incoming message. But agentBuffer appears to be null everytime, so that I see no way to affect the message data.

Any clue would be appreciated.

UPD I was wrong about agentBuffer is always null, it is not. Following T.Rob answer I managed to catch several calls with MQCXP.ExitReason = 14 (MQXR_XMIT). With one of these calls I receive message data in buffer, and it looks possible to modify such data. But still, there is a problem with other calls, having the same ExitReason, but not corresponding to any real message transmission. I need to skip such calls, but yet have no idea how to distinguish them.

Any idea how can I do it?

Upvotes: 2

Views: 563

Answers (2)

Roger
Roger

Reputation: 7456

Coding an exit in MQ is extremely difficult and requires an indepth knowledge of MQ. A SVRCONN/CLNTCONN channel pair has bi-directional traffic flow on it and you do NOT see the whole message (unless it is less than 32758 bytes). What you see in a channel send/receive exit are Transmission Segment Header (TSH) messages. Note: TSH messages are NOT documented by IBM!!!

The MCA (Message Channel Agent) invokes a channel send/receive exit for various 'ExitReason' defined by MQXR_***.

But agentBuffer appears to be null everytime, so that I see no way to affect the message data.

That is because you do not understand MQ nor the flow of the bidirectional channel. You do realize that the TSH messages are in binary not plain text!?! Right? Are you dumping/printing the buffer in HEX or doing System.out.println?? If the latter then see my first sentence in this post.

Use a debugger and view the TSH data. Please don't ask why you are looking at weird stuff as I said, TSH messages are NOT documented by IBM! If you want information then go look at the code for Wire Shark as they have reverse engineered the TSH messages.

Finally, why are you writing a channel send/receive exit as there are many other ways to accomplish looking at message flow than using an exit.

Upvotes: 2

T.Rob
T.Rob

Reputation: 31832

There are several kinds of channel exit in MQ. The MCA channels (QMgr-to-QMgr) make an exit point available when the entire message is in the buffer. This exit point invokes the Message Exit. All channels, MCA and MQI (client), make Send/Receive exit points available. The Send/Receive exit points are exercised any time that a transmission from one channel agent to another is invoked.

In the case of client channels, the receive exit may be invoked for flows that do not include message transport, or they may be invoked many times for a single message. It is up to the program to check the MQCXP structure to determine the API call that is flowing over the client channel and whether the agent buffer should or should not contain anything at that point in time.

Note that Send and Receive exits normally work in pairs. Since the queue manager does not invoke Java programs from the MCA, any corresponding Send or Receive exit on the queue manager's side would be written in C.

See the manual page on Channel send and receive exit programs for more info.

Upvotes: 4

Related Questions