|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ Put Message Exception Handling |
« View previous topic :: View next topic » |
Author |
Message
|
dahacker |
Posted: Wed Jul 20, 2005 11:01 am Post subject: MQ Put Message Exception Handling |
|
|
Newbie
Joined: 20 Jul 2005 Posts: 5
|
Environment: C#, .NET, WIN2K3 Server
I have a class method i call to write a message to MQ. The only difficulty I am having is deciding how generic to make my exception handling.
Simply put, i want to resend the message if, for some reason, the message was not written to the queue. Is is at simple as catching warnings versus failures? If is is a warning and not a failure, how do i know the message got written or not? And i want to use one try{} catch{} block for the whole method, not try{} catch{} for each API call...
That is, if i don't want to parse for specific reason codes, then do i have to try catch for creating the MQ connection, writing, and disconnecting? if i successfully write, but fail on my close, i don't want to resend the message...
i just want something easy. any tips?
thanks, |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jul 20, 2005 11:32 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Something easy is to crib code from a sample program...
More informatively, there are cases where no matter what you do, you will not be able to successfully put a message - for instance, if the open fails.
In this case, having a single response to all errors will not lead to success... as per the old definition of insanity as "trying the exact same thing and expecting different results"...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
dahacker |
Posted: Thu Jul 21, 2005 1:02 pm Post subject: |
|
|
Newbie
Joined: 20 Jul 2005 Posts: 5
|
is there a possibilty of raising an exception on Close() or Disconnect()? Let's say I catch an exception after I have established the connection and successfully Put(), i dont wan't to loop all the way back up and reconnect and send, i just want to make sure i close cleanly and that my resources are freed in MQ...
so far I have:
/*
* MQ
*/
while(bTryAgain)//init to true
{
try
{
/*
* Create an MQ context and connect.
*/
MQQueueManager mq_QMgr = new MQQueueManager(oQueue.Manager_Name, oQueue.Channel, oQueue.Host);
MQQueue mq_Q = mq_QMgr.AccessQueue(oQueue.Name, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
/*
* Create an MQ message object and set it to the current message to send...
*/
MQMessage mq_Message = new MQMessage();
MQPutMessageOptions mq_MessageOptions = new MQPutMessageOptions();
byte[] MessageID; //contains the message id value for conversion to string for logging
mq_Message.WriteString(oQueueMessage.Value); //write data into message
mq_Message.Format = MQC.MQFMT_STRING; //init format
/*
* Write the message to the queue...
*/
while(bTryAgain)
{
bTryAgain = false;
try
{
mq_Q.Put(mq_Message, mq_MessageOptions); //write to queue
bTryAgain = false; //if we get here, put worked, don't resend...
}
catch(MQException mq_ex)
{
LogManager.Publish(new LogMessage("A WebSphere MQ error occurred.", "Completion code: " + mq_ex.CompletionCode.ToString() + "Reason code: " + mq_ex.ReasonCode.ToString()));
System.Threading.Thread.Sleep(1000);
bTryAgain = true; //there was an exception, resend (warnings?)
}
}
/*
* convert message ID to string
*/
MessageID = mq_Message.MessageId;
string sMessageID = "";
for(int i=0; i<MessageID.Length; i++)
{
sMessageID += MessageID[i].ToString();
}
/*
* set oQueueMessage values for 'return' by ref
*/
oQueueMessage.MessageID = sMessageID;
oQueueMessage.TimeStamp_Local = mq_Message.PutDateTime.ToLocalTime().ToString();
oQueueMessage.TimeStamp_MQ = mq_Message.PutDateTime.ToString();
oQueueMessage.Status = Enums.MessageStatus.Alive.GetHashCode();
/*
* close and diconnect, clean up
*/
mq_Q.Close();
mq_QMgr.Close();
mq_QMgr.Disconnect();
mq_QMgr = null;
mq_Q = null;
mq_Message = null;
mq_MessageOptions = null;
sMessageID = null;
}
catch(MQException mq_ex)
{
LogManager.Publish(new LogMessage("A WebSphere MQ error occurred.", "Completion code: " + mq_ex.CompletionCode.ToString() + "Reason code: " + mq_ex.ReasonCode.ToString()));
}
}//end MQ while |
|
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
|
|
|
|