Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //create queue
- try
- {
- //create MSMQ
- $Query = new COM("MSMQ.MSMQQuery");
- // if($Query->LookupQueue(0,0,'TestQueue')){
- $MSMQInfo = new COM("MSMQ.MSMQQueueInfo");
- $MSMQInfo->PathName = '.\testqueue';
- $MSMQInfo->Label = "TestQueue";
- $MSMQInfo->Create;
- echo "MSMQ Queue: Successfully Created <br />";
- // }
- // else
- // {
- // echo "MSMQ Queue: MSMQ Queue Already exists<br />";
- // }
- //send message to MSMQ
- //set destination
- $DEST = new COM("MSMQ.MSMQDestination");
- $DEST->PathName = '.\testqueue';
- echo "MSMQ Queue: Destination Queue Set<br />";
- //create msg
- $MSG = new COM("MSMQ.MSMQMessage");
- for($b=0;$b<10;$b++)
- {
- $MSG->Label = 'Test Message '.$b;
- $MSG->Body = "Test message ".$b." body";
- $MSG->Send($DEST);
- }
- echo "MSMQ Queue: ".$b." Message(s) Sent<br />";
- //read queue
- //open MSMQ
- $READ = $MSMQInfo->Open(2,0);
- echo "MSMQ Queue: ".$MSMQInfo->PathName." opened <br />";
- $i=1;
- foreach($READ->PeekCurrent() AS $R_MSG):
- echo '[ MSG '.$i.' ]'.$R_MSG->Label.': '.$R_MSG->Body.'<br />';
- $i++;
- endforeach;
- //close MSMQ
- $READ->Close();
- }
- catch (Exception $e)
- {
- echo 'Caught exception: ', $e->getMessage(), "<br />";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement