try
{
mqQMgr = new MQQueueManager( strQueueManagerName );
}
catch( MQException mqe )
{
string strError = mqrcText.getMQRCText( mqe.Reason );
MessageBox.Show( "Error trying to create Queue " +
"Manager Object. Error: " + mqe.Message +
", Details: " + strError );
return;
}
//Step 2. Open Request Queue for writing our request
try
{
requestQueu e = mqQMgr.AccessQueue( strRequestQueueName,
MQC.MQOO _OUTPUT // open queue for output
+ MQC.MQOO_FAIL_IF_QUIESCING ); // but not if
// MQM stopping
}
catch( MQException mqe )
{
//...
}
//Step 3. Open Response Queue for reading the response.
//Note: You can do this AFTER writing the request too.
//Depends on the protocol you are using - may be you
//are not supposed to write the request unless you
//ensure that you are listening for response too. If
//that is not the case, you can do this after writing
//the request message (before step 5).
try
{
responseQueue = mqQMgr.AccessQueue( strResponseQueueName,
MQC.MQO O_INPUT_AS_Q_DEF // open queue for input
+ MQC.MQOO_FAIL_IF_QUIESCING ); // but not if MQM stopping
}
catch( MQException mqe )
{
//...
}
//Step 4. PUT Request Message in Request Queue. Note the options
//needed to be set. Note that once PUT is successful, you can close
//the Request Queue. Note that you are asking whoever receives this
//request to copy the MSG ID to CORREL ID so that you can later
//"match" the response you get with the request you sent.
try
{
requestMessag e = new MQMessage();
requestMessage.W riteString( strRequestText );
requestMessage.Format = MQC.MQFMT_STRING;
requestMess age.MessageType = MQC.MQMT_REQUEST;
requestMess age.Report = MQC.MQRO_COPY_MSG_ID_TO_CORREL _ID;
requestMessage.ReplyToQu eueNam e = strResponseQueueName;
request Message.ReplyToQueueMan agerName = strQueueManagerName;
requestQ ueue.Put(requestMessag e);
if( requestQueue.OpenStatus )
requestQueue.Close();
if( MessageBox.Show("Request Message PUT successfully.\nOK: " +
"wait for RESPONSE, Cancel: skip waiting", "Do you want to " +
"wait for response?", MessageBoxButtons.OKCancel ) ==
DialogResult.Cancel)
{
i f( responseQueue.OpenStatus )
responseQueue.Close();
if( mqQMgr.ConnectionStatus )
mqQMgr.Disconnect();
retur n;
}
}
catch( MQException mqe )
{
//...
}
//Step 5. Read the response from response
//queue. Note the options to be set.
//It may happen that you get no response.
//Also note that you decide how long you wait
//for the response. In order to get the
//response, note the "matching" criterion.
try
{
response Message = new MQMessage();
responseMessage. CorrelationId = requestMessage.MessageId;
MQG etMessageOptions gmo = new MQGetMessageOptions();
gmo.Op tions = MQC.MQGMO_WAIT;
if( nud_PRGBR_WaitMS.Enabled == true )
gmo.WaitInterval = ( int ) nud_PRGBR_WaitMS.Value;
else
gmo.WaitInterval = MQC.MQWI_UNLIMITED;
gmo.Match Options = MQC.MQMO_MATCH_CORREL_ID;
r esponseQueue.Get(responseMess age, gmo);
tb_PRGBR_RESPONSE_TEXT. Text =
responseMessage.ReadString( res ponseMessage.MessageLength);
}
catch( MQException mqe )
{
//...
}
//Step 6. Close Response Queue, Disconnect Manager.
//Note that you have already closed the request
//queue in step 4.
if( responseQueue.OpenStatus )
responseQueue.Close();
if( mqQMgr.ConnectionStatus )
mqQMgr.Disconnect();
retur n;
Answered by
Shobhit
, an ibibo Master,
at
12:23 PM on August 20, 2008