Exemplo n.º 1
0
 /**
  * @test
  */
 public function purgeShouldResultInAnEmptyQueue()
 {
     $this->adapter->purge();
     for ($x = 10; $x <= 10; $x++) {
         $this->adapter->enqueue("message {$x}", 'tenhunen');
     }
     list($msg, $identifier, $internals) = $this->adapter->dequeue();
     $this->assertInternalType('string', $msg);
     $this->adapter->ack($identifier, $internals);
     $this->adapter->purge();
     $this->assertFalse($this->adapter->dequeue());
 }
Exemplo n.º 2
0
 /**
  * @param string $topic
  * @param mixed $data
  * @return Message
  * @throws RuntimeException
  */
 public function enqueue($topic, $data = null)
 {
     $serializer = $this->dataSerializers->getSerializerFor($data);
     if (!$serializer) {
         throw new RuntimeException("Serializer not found");
     }
     $serializedData = new SerializedData($serializer->getIdentifier(), $serializer->serialize($data));
     $message = Message::create($topic, $data);
     $arr = array('uuid' => $message->getUuid(), 'topic' => $message->getTopic(), 'data' => $serializedData->toJson());
     $json = json_encode($arr);
     $json = $this->outputFilters->filter($json);
     try {
         $this->adapter->enqueue($json, $topic);
         return $message;
     } catch (\Exception $e) {
         throw new RuntimeException('Queuing a message failed', 0, $e);
     }
 }