I manage to retrieve one message from the given topic, but when I try to retrieve another one, it just fails, even though there are messages on the topic. The code is the same as IBM provided sample code, except that destForGet.Get(messageForGet);
is in a while loop with some time to wait set in the options. Another client puts messages to the topic, and that works. The first message is received, but all others are not. The sample code snippet is given hereafter:
// bool RunThread is managed from some other thread; irrelevant for this snippet
// MQTopic destForGet is initialized earlier; irrelevant for this snippet
MQMessage messageForGet = new MQMessage();
MQGetMessageOptions mgo = new MQGetMessageOptions();
mgo.Options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_SYNCPOINT;
mgo.WaitInterval = 500;
string subName = "SampleSubscription";
while (RunThread)
{
try
{
DestForGet.Get(messageForGet, mgo);
}
catch (MQException mqE)
{
Console.WriteLine("MQException caught. " + mqE.ToString());
}
}
If I instantiate messageForGet within the while loop, then it works, but that seems to be very ineffective (to constantly allocate/deallocate memory). Also, messageForGet.ClearMessage()
does not help in the matter. Is there a way to retrieve multiple messages from the topic, without instantiating each individual message?