Beispiel #1
0
 public static function run()
 {
     while (true) {
         $messageQueue = MessageQueue::getInstance();
         $message = $messageQueue->getMessage();
         if (false == $message) {
             print "no message in message queue\n";
             sleep(20);
         }
         /*
          * Write code here to process the $message
          *
          *
          *
          *
          *
          *
          *
          *
          *
          */
         /*
          * When finish process the $message,,ack the message
          */
         $ret = DBUnACKQueue::ackMessage($message);
         if (false == $ret) {
             print "failed to ack message: {$message}\n";
             sleep(10);
         } else {
             print "finish ack: {$message}\n";
         }
     }
 }
Beispiel #2
0
 public static function checkQueue()
 {
     $redis = DBConnect::getRedisServer();
     $messageArray = $redis->lRange(KeyNamespace::UN_ACK_QUEUE, 0, -1);
     foreach ($messageArray as $message) {
         $executeTime = substr($message, strlen(KeyNamespace::UN_ACK_QUEUE) + 1, strlen($message));
         $lastTime = time() - (int) $executeTime;
         if ($lastTime > UnACKQueueConfig::TIME_INTERVAL) {
             //ignore the return
             DBUnACKQueue::moveMessageToFailedQueue($message);
         }
     }
 }
Beispiel #3
0
 public static function run()
 {
     while (true) {
         DBUnACKQueue::checkQueue();
     }
 }