Example #1
0
 /**
  * Pops a message.
  *
  * @return array An array with the following keys:
  *               _id, receiver and body
  *
  * @throws EmptyQueueInternalException
  */
 public function pop()
 {
     $item = $this->connectToStorageInternalWorker->connect()->find()->sort(['_id' => 1])->limit(1)->getNext();
     if (!$item) {
         throw new EmptyQueueInternalException();
     }
     $this->connectToStorageInternalWorker->connect()->remove(array('_id' => $item['_id']));
     return $item;
 }
Example #2
0
 /**
  * Creates a message.
  *
  * @param string $receiver
  * @param string $body
  *
  * @return string The already created message's id.
  */
 public function enqueue($receiver, $body)
 {
     $message = uniqid();
     $this->connectToStorageInternalWorker->connect()->insert(array('message' => $message, 'receiver' => $receiver, 'body' => $body));
     return $message;
 }
 /**
  * Collects messages.
  *
  * @return \Iterator
  */
 public function collect()
 {
     return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]);
 }