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"; } } }
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); } } }
public static function run() { while (true) { DBUnACKQueue::checkQueue(); } }