ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ API SupportUsing MQMHBUF overwrites message data

Post new topicReply to topic
Using MQMHBUF overwrites message data View previous topic :: View next topic
Author Message
hopsala
PostPosted: Sun May 05, 2019 4:28 am Post subject: Using MQMHBUF overwrites message data Reply with quote

Guardian

Joined: 24 Sep 2004
Posts: 960

So here's my scenario:
I am writing an MQ API Exit (yes, this is necessary, please let's put that discussion aside for now...), hooking into the PutBefore entry point.

Let's say that the user does an MQPUT with an RFH2 header, containing the property:
<usr><prop>1</prop></usr>.

What I want to do is increment the property value, so that the message on the queue will contain an RFH2 with:
<usr><prop>2</prop></usr>

(If the user does an MQPUT with the property in a message handle on MQPMO.MsgHandle, rather than injecting an RFH2 header directly into the buffer, then this becomes a lot easier. But in this case the RFH2 is injected into the buffer directly)

Here's a simplified code of what I'm trying to do:
Code:
// convert RFH2 properties to message handle
MQBUFMH(&Hmsg... buflen, datalen, buffer...) 

// get "prop" value from handle
i = MQINQMP(&Hmsg, "prop")

// increment "prop" within the handle
MQSETMP(&Hmsg, "prop", i+1)

// convert the handle back to RFH2 and put it into the message buffer
MQMHBUF(&Hmsg... buflen, datalen, buffer) 


However, after trying this I found that the resulting buffer of MQMHBUF *overwrites* existing message payload. So for example, if buffer is
Quote:
{RFH2...helloworlddata}

and the new RFH2 is longer (which it is), then MQMHBUF results in this buffer:
Quote:
{longerRFH2...orlddata}.


This is a problem. It means I need to manually discover where the payload starts, create a bigger buffer, and insert the new RFH2 right before the payload. It's possible, but it's quite messy, and who knows what edge cases I'll come across if I start traversing the buffer bit by bit (MQ versioning, RFH v1/v2, other RFH2 folders...)
Is expected behavior? I thought the whole purpose of MQMHBUF is to spare us building the buffer manually

I'm also wondering what this means for other RFH2 fields like jms/mcd etc. Will they be overwritten too?

Has anyone else come across this? There are no examples of MQMHBUF that I could find online or in the lit

Many thanks
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun May 05, 2019 9:33 pm Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20021
Location: LI,NY

I believe you will need 2 buffers, the message properties handle and the message handle buffers. You will need to reset them both and determine the full length of data and properties.

You should then be able to update seemlessly any property...
You'd also have to verify that all the tasks done behind the scene on the put are also done when you run your exit...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hughson
PostPosted: Mon May 06, 2019 9:51 am Post subject: Re: Using MQMHBUF overwrites message data Reply with quote

Grand Master

Joined: 09 May 2013
Posts: 1139
Location: Bay of Plenty, New Zealand

hopsala wrote:
However, after trying this I found that the resulting buffer of MQMHBUF *overwrites* existing message payload. So for example, if buffer is
Quote:
{RFH2...helloworlddata}

and the new RFH2 is longer (which it is), then MQMHBUF results in this buffer:
Quote:
{longerRFH2...orlddata}.

That's because you are pointing it to the same buffer. MQMHBUF is only handling the Message Handle (MH) contents into a Buffer (BUF), not the whole message payload.

You must use a separate buffer.

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ API SupportUsing MQMHBUF overwrites message data
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.