public function test_MessageTest__make() { $this->object = new Client($this->queueClient, [Store::MESSAGE_BODY => 'body']); $this->assertInstanceOf('zaboy\\async\\Message\\Client', $this->object); $this->assertTrue($this->object->isId($this->object->getId())); $this->assertEquals('body', $this->object->getBody()); $this->assertEquals(1, $this->object->getStore()->count([Store::QUEUE_ID => $this->queueClient->getId()])); $this->object->remove(); $this->assertEquals(0, $this->queueClient->getNumberMessages()); }
/** * @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); } }