Advertisement
Guest User

Example PHP MSMQ script

a guest
May 1st, 2012
2,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. //create queue
  4. try
  5. {
  6.     //create MSMQ
  7.     $Query = new COM("MSMQ.MSMQQuery");
  8.     // if($Query->LookupQueue(0,0,'TestQueue')){
  9.         $MSMQInfo = new COM("MSMQ.MSMQQueueInfo");
  10.         $MSMQInfo->PathName = '.\testqueue';
  11.         $MSMQInfo->Label = "TestQueue";
  12.         $MSMQInfo->Create;
  13.         echo "MSMQ Queue: Successfully Created <br />";
  14.     // }
  15.     // else
  16.     // {
  17.         // echo "MSMQ Queue: MSMQ Queue Already exists<br />";
  18.     // }
  19.     //send message to MSMQ
  20.     //set destination
  21.     $DEST = new COM("MSMQ.MSMQDestination");
  22.     $DEST->PathName = '.\testqueue';
  23.     echo "MSMQ Queue: Destination Queue Set<br />";
  24.     //create msg
  25.     $MSG = new COM("MSMQ.MSMQMessage");
  26.     for($b=0;$b<10;$b++)
  27.     {
  28.         $MSG->Label = 'Test Message '.$b;
  29.         $MSG->Body = "Test message ".$b." body";
  30.         $MSG->Send($DEST);
  31.     }
  32.    
  33.     echo "MSMQ Queue: ".$b." Message(s) Sent<br />";
  34.     //read queue
  35.     //open MSMQ
  36.     $READ = $MSMQInfo->Open(2,0);
  37.     echo "MSMQ Queue: ".$MSMQInfo->PathName." opened <br />";
  38.     $i=1;
  39.     foreach($READ->PeekCurrent() AS $R_MSG):
  40.             echo '[ MSG '.$i.' ]'.$R_MSG->Label.': '.$R_MSG->Body.'<br />';
  41.             $i++;
  42.     endforeach;
  43.     //close MSMQ
  44.     $READ->Close();
  45. }
  46. catch (Exception $e)
  47. {
  48.     echo 'Caught exception: ',  $e->getMessage(), "<br />";
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement