function index()
 {
     $req = $this->getRequest()->requestVars();
     $queue = $req && isset($req["queue"]) ? $req["queue"] : null;
     $limit = $req && isset($req["limit"]) ? $req["limit"] : null;
     // Work out what processes need to be run. Tries 'actions' and 'action', which are synonyms.
     if ($req && isset($req["actions"])) {
         $actions = $req["actions"];
     } else {
         if ($req && isset($req["action"])) {
             $actions = $req["action"];
         } else {
             $actions = "all";
         }
     }
     $retrigger = $req && isset($req["retrigger"]) ? $req["retrigger"] : "";
     $actions = explode(",", $actions);
     $flush = false;
     $consume = false;
     foreach ($actions as $a) {
         if ($a == "flush" || $a == "all") {
             $flush = true;
         }
         if ($a == "consume" || $a == "all") {
             $consume = true;
         }
     }
     if ($flush) {
         MessageQueue::flush($queue);
     }
     if ($consume) {
         $count = MessageQueue::consume($queue, $limit ? array("limit" => $limit) : null);
         if (!$count) {
             return $this->httpError(404, 'No messages');
         }
     }
     if ($retrigger == "yes") {
         // @todo This assumes the queue is simpleDBMQ. Not performant on long queue.
         // @todo Generalise counting.
         $count = DB::query("select count(*) from \"SimpleDBMQ\" where \"QueueName\"='{$queue}'")->value();
         if ($count > 0) {
             MessageQueue::consume_in_subprocess($queue);
         }
     }
     return 'True';
 }
 /**
  * Test that when a message is delivered by callback, the message disappears
  * off the queue, and the message we get is as we expect.
  */
 function testCallbackDelivery()
 {
     MessageQueue::add_interface("default", array("queues" => array("testmainqueue"), "implementation" => "SimpleDBMQ", "encoding" => "php_serialize", "send" => array("onShutdown" => "none"), "delivery" => array("callback" => array("MessageQueueTest", "messageCallback"), "onerror" => array("requeue"))));
     $this->assertTrue($this->getQueueSizeSimpleDB("testmainqueue") == 0, "Main queue is empty before we put anything in it");
     MessageQueue::send("testmainqueue", new MethodInvocationMessage("MessageQueueTest", "doStaticMethod", "p1", 2));
     $this->assertTrue($this->getQueueSizeSimpleDB("testmainqueue") == 1, "Main queue has an item after we add to it");
     self::$message_frame = null;
     // clear the queue, causing the callback to be executed, which will leave the message in self::$message_frame
     MessageQueue::consume("testmainqueue");
     // Check there is nothing in testmainqueue, and now something in testerrorqueue
     $this->assertTrue($this->getQueueSizeSimpleDB("testmainqueue") == 0, "Main queue is cleared after consumption");
     $this->assertTrue(self::$message_frame != null, "Message has been captured");
     $this->assertTrue(self::$message_frame->body != null, "Message has body");
     $this->assertTrue(self::$message_frame->body instanceof MethodInvocationMessage, "Message is the same type of object we sent");
 }
예제 #3
0
<?php

$argv = $_SERVER['argv'];
if (count($argv) != 2) {
    echo "参数不合法\r\n";
    exit;
}
$queueName = $argv[1];
$callBack = isset(MessageQueueConfig::$callBack[$queueName]) ? MessageQueueConfig::$callBack[$queueName] : array();
if (!empty($callBack) && !empty($callBack['callBackClassName']) && !empty($callBack['callBackMethod'])) {
    MessageQueue::consume($queueName, array($callBack['callBackClassName'], $callBack['callBackMethod']));
} else {
    echo "队列:{$queueName},回调配置出错\r\n";
}