Author |
Message
|
bhu |
Posted: Wed Sep 13, 2006 6:57 am Post subject: How to skip Message and move to the next one. |
|
|
Novice
Joined: 27 Jun 2006 Posts: 19
|
we are writing a batch process which will open the queue manger and starts reading the message one by one and do some work.
for some reason the work it does fails then we need to skip to the next message, how can we do this ?
the code is
queueManger = new MQQueueManager(QueueManagerName,channelName,connectionName);
queue = queueManger.AccessQueue(QueueName,MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
MQGetMessageOptions oGetMsgOption = new MQGetMessageOptions();
oGetMsgOption.Options = MQC.MQPMO_SYNCPOINT;
while(queue.CurrentDepth > 0)
{
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
queue.Get(queueMessage,oGetMsgOption);
OrderAckWS(queueMessage.ReadString(queueMessage.MessageLength)); //Failed need to skip here
queueManger.Commit();
}
queue.Close();
queueManger.Disconnect();
any idea
thanks
bhu |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 13, 2006 7:48 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Define "skip"?
Do you mean "leave on the queue"? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bhu |
Posted: Wed Sep 13, 2006 8:06 am Post subject: |
|
|
Novice
Joined: 27 Jun 2006 Posts: 19
|
yes i mean leave it on the queue, and move to the next message,
when this batch runs again it will pick that message again, if error occurs again leave it and move to the next one.
thanks
bhu |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 13, 2006 8:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You could skip the commit if an error occurs.
That would leave the message in an uncommitted get, and the next get would get the first uncommitted message.
Then do a rollback as the final step in your code, or otherwise make sure a rollback occurs. (read up on explicit versus implicit rollbacks).
The problem with this is that it's hard on the system and hard on the logs and etc.
Another option is to use a combination of Browse and destructive gets.
Both of these options mean that the queue is going to fill up over time with unprocessable messages.
This is why the recommended design pattern is to use a backout queue. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
tleichen |
Posted: Wed Sep 13, 2006 8:18 am Post subject: |
|
|
Yatiri
Joined: 11 Apr 2005 Posts: 663 Location: Center of the USA
|
bhu wrote: |
yes i mean leave it on the queue, and move to the next message,
when this batch runs again it will pick that message again, if error occurs again leave it and move to the next one.
thanks
bhu |
If the first message fails processing, why would the second one not? Is the nature of the data varying, such that the process would vary as well? If so, maybe your MQSeries architecture needs to be reworked, as it sounds like you have varying types of messages on the same queue, that would be better facilitated on multiple queues. Just my two cents...  _________________ IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer |
|
Back to top |
|
 |
bhu |
Posted: Wed Sep 13, 2006 10:12 am Post subject: |
|
|
Novice
Joined: 27 Jun 2006 Posts: 19
|
the messages are same, but say when we read the message and update a database and let u ssay it failed, due various reasons , basically i don;t want to come out of the program instead it will send a notification (Email) and move to the next message and update the database.
and we can go and find out what the issue with the database for that particular message and correct if possible.
thanks
bhu |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 13, 2006 10:14 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
This is exactly the kind of thing a backout queue is designed for. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bhu |
Posted: Wed Sep 13, 2006 12:10 pm Post subject: |
|
|
Novice
Joined: 27 Jun 2006 Posts: 19
|
can u please tell me how to do it the (back out Queue ) or point to some sample. I want to Try it.
thanks
bhu |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 13, 2006 12:21 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
basically, you just use Backout to fail the transaction. Then, when you get a message you check if the Backout count on the MQMD is greater than the Backout Threshold on the queue, and if it is then instead of backing the message out you put it to the Backout Queue named on the queue def. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sanvij |
Posted: Wed Sep 13, 2006 12:25 pm Post subject: |
|
|
Novice
Joined: 21 Mar 2003 Posts: 24
|
When a message fails to get processed the application should move the message to a ERROR /POINSON queue. This will clear the path for the forth coming messges to be worked on. _________________ Sanvij
IBM Certified MQSeries Specialist
IBM Certified WebSphere MQ Solution Designer |
|
Back to top |
|
 |
|