|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQGET: buffer size |
« View previous topic :: View next topic » |
Author |
Message
|
watt01 |
Posted: Thu Aug 01, 2002 1:20 pm Post subject: MQGET: buffer size |
|
|
Newbie
Joined: 03 Jun 2002 Posts: 6
|
Hi everyone,
Have a question on MQGET using C/C++:
I need to allocate just enough memory to retrieve message using MQGET. What is the best way to know the size of the next message that will be retrieved using MQGET?
I would imagine code like this:
int nsize;
char *buff;
xxxxxx(Hconn, Hobj, ....); <---- Statement #1
//the call to xxxxxx will populate nsize.
buff=new char[nsize+1];
MQGET (
Hconn, Hobj, &MsgDesc, GetMsgOpts, nsize ...); <---- Statement #2
As in the code, I will call the magical function xxxxxx which will populate the next message size somewhere (say nsize)
Once nsize is known, then the buffer can be allocated and passed to MQGET.
However, there is a glitch. What if some other process inserts a high priority message between the time we call statement #1 and #2? In such a case, nsize will no longer be valid.
Any help, thoughts, comments will be highly appreciated.
Thanks in advance!! |
|
Back to top |
|
 |
simonson |
Posted: Thu Aug 01, 2002 1:52 pm Post subject: |
|
|
Novice
Joined: 17 Apr 2001 Posts: 15
|
If you perform a get with a buffer set to 0 length, the get will fail. However you will have access to the message length returned in the get call. You can then set the buffer to the size needed and repeat the get. However, remember if you are running multiple programs that are doing gets, then there is no guarantee that you will get the message you first looked at. However, if you capture the message id in the mqmd when you do the first get, and always specify that message id when you do the second get you will get only that message, unless some other program already got it. If you are the only program doing gets from the queue, you won't have to worry about the message id. Have fun.  |
|
Back to top |
|
 |
watt01 |
Posted: Thu Aug 01, 2002 3:49 pm Post subject: |
|
|
Newbie
Joined: 03 Jun 2002 Posts: 6
|
|
Back to top |
|
 |
kingsley |
Posted: Thu Aug 01, 2002 8:02 pm Post subject: |
|
|
Disciple
Joined: 30 Sep 2001 Posts: 175 Location: Hursley
|
Hi,
Lock the messaage using MQGMO_LOCK
Next you read the message using GET after allocating the required memory.
That's simple and healthy way |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|