Exemplo n.º 1
0
 /**
  * @param string $priority
  *
  */
 public function pullMessage($priority = null)
 {
     try {
         $errorMsg = "Can't start transaction for the method pullMessage";
         $this->store->beginTransaction();
         //is row with this index exist?
         $errorMsg = "Can't execute the method pullMessage";
         $db = $this->messagesStore->getAdapter();
         $sql = new Sql\Sql($db);
         $priorityWhere = is_null($priority) ? [MessageStore::QUEUE_ID => $this->getId()] : [MessageStore::QUEUE_ID => $this->getId(), MessageStore::PRIORITY => $priority];
         $select = $sql->select()->from($this->messagesStore->getTable())->order([MessageStore::PRIORITY . ' DESC', MessageStore::CREATION_TIME])->where($priorityWhere)->limit(1, 0);
         $statement = $sql->prepareStatementForSqlObject($select);
         $rowset = $statement->execute();
         $data = $rowset->current();
         if (false === $data) {
             $this->messagesStore->commit();
             return null;
         }
         $messageId = $data[MessageStore::ID];
         $message = new MessageClient($this, $messageId);
         $messageBody = $message->getBody();
         $promise = $message->getPromise();
         $this->deleteMessage($message->getId());
         $promise->resolve($messageBody);
         $this->messagesStore->commit();
         return $messageBody;
     } catch (\Exception $e) {
         $this->messagesStore->rollback();
         throw new QueueException($errorMsg . 'Queue : ' . $this->getName(), 0, $e);
     }
 }