Author |
Message
|
Woo-Shoo, Jeong |
Posted: Tue Jul 18, 2006 4:47 pm Post subject: message Get problem |
|
|
Newbie
Joined: 18 Nov 2005 Posts: 5
|
Hello!
I have a Queue. There are many messages in the Queue.
I want to get message from that Queue. But I don't know length of message.
To get message using Sample C Source(mqget), I must know length of message. But I don'know.
Prior to run Get sample code, Is there any method to know length of message. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jul 18, 2006 11:23 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Three methods I can think of:
1) Browse the message; this will set the message length parameter in the MQGET call. Set the message buffer to this length and do the destructive get
or my preferred option:
2) Set the buffer to the size of the largest message you think is likely and put in error handling to trap the truncated message condition. Most of the gets will suceed because the buffer is large enough. Those that fail, reset the buffer using the length parameter as above
or finally
3) Set the buffer to the max message length of the queue!!
(Clearly 3 may be unsuitable if you're short on memory and/or have a very large max length. It's also vunerable to some administrator changing the max length at some future point, but it's head and shoulders the easiest to implement )
Have fun now  _________________ Honesty is the best policy.
Insanity is the best defence.
Last edited by Vitor on Wed Jul 19, 2006 12:43 am; edited 1 time in total |
|
Back to top |
|
 |
Nigelg |
Posted: Wed Jul 19, 2006 12:35 am Post subject: |
|
|
Grand Master
Joined: 02 Aug 2004 Posts: 1046
|
All of Vitor's solutions may have problems.
1. |You should do browse with LOCK, and then MSG_UNDER_CIRSOR, to make sure that the destructive get is returned the same msg as the browse.
If you are doing CONVERT, you should bear in mind that the msg may expand on conversion if converting to UTF-8 or any other MBCS code page, and adjust the buffer size accordingly.
2. Rather wasteful of memory, and suffers from the same problem as the browse in that the get after the truncated msg may not get the same msg. There is no equivalent of MSG_UNDER_CURSOR for a second destructive get, but you could read the msg the second time by MsgId, if they are unique on your system.
3. Definitely wasteful on memory! _________________ MQSeries.net helps those who help themselves.. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jul 19, 2006 12:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Nigelg
I do take your points, especially the importance of browse with lock which I omitted from my original post!
Option 2 is only wasteful of memory if you have a message significantly larger than the average which infrequently occurs. It's a matter of design and therefore allows no "right" answer; I prefer to have message types grouped one to a queue and hence a very even distribution of lengths.
Option 3 - I don't think "wasteful" quite covers it! Dead simple to code though.... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jul 19, 2006 1:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Memory is cheaper than downtime or dropped messages. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
PeterPotkay |
Posted: Wed Jul 19, 2006 5:59 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
Nigelg wrote: |
All of Vitor's solutions may have problems.
1. |You should do browse with LOCK, and then MSG_UNDER_CIRSOR, to make sure that the destructive get is returned the same msg as the browse.
If you are doing CONVERT, you should bear in mind that the msg may expand on conversion if converting to UTF-8 or any other MBCS code page, and adjust the buffer size accordingly.
|
Or open the queue exclusivly, and skip the browsing altogether. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
belchman |
Posted: Mon Jul 24, 2006 9:39 am Post subject: |
|
|
Partisan
Joined: 31 Mar 2006 Posts: 386 Location: Ohio, USA
|
Or download and use supportpac MA01 |
|
Back to top |
|
 |
|