public function listen(array $commandHandlers)
 {
     $this->init();
     $callback = function ($req) use($commandHandlers) {
         $command = $this->serializer->deserialize(json_decode($req->body, true));
         foreach ($commandHandlers as $commandHandler) {
             if ($this->hasHandleMethodFor($commandHandler, $command)) {
                 try {
                     $commandHandler->handle($command);
                     $message = json_encode(['status' => 'succes']);
                 } catch (\Exception $e) {
                     $message = json_encode(['status' => 'error', 'message' => $e->getMessage()]);
                 }
                 $msg = new AMQPMessage((string) $message, array('correlation_id' => $req->get('correlation_id')));
                 $req->delivery_info['channel']->basic_publish($msg, '', $req->get('reply_to'));
             }
         }
         $req->delivery_info['channel']->basic_ack($req->delivery_info['delivery_tag']);
     };
     $this->channel->basic_consume($this->queueName, '', false, false, false, false, $callback);
     while (count($this->channel->callbacks)) {
         $this->channel->wait();
     }
     $this->channel->close();
     $this->connection->close();
 }
 /**
  * @return ReadModelInterface[]
  */
 public function findAll()
 {
     $statement = $this->connection->prepare(sprintf('SELECT serialized FROM %s WHERE class = :class', static::TABLE));
     $statement->execute(['class' => $this->class]);
     return array_map(function ($row) {
         return $this->serializer->deserialize(json_decode($row['serialized'], true));
     }, $statement->fetchAll(\PDO::FETCH_ASSOC));
 }
 /**
  * @param string $message
  *
  * @return DomainMessage
  */
 private function deserializeDomainMessage($message)
 {
     return $this->serializer->deserialize(json_decode($message, true));
 }
 /**
  * Deserialize json after it's been converted to associated arrays
  */
 private function deserialize($json)
 {
     return $this->serializer->deserialize(json_decode($json, true));
 }
 /**
  * @param $result
  *
  * @return array
  */
 private function deserialize($result)
 {
     return $this->serializer->deserialize($result);
 }
Example #6
0
 /**
  * @param $row
  * @return DomainMessage
  */
 protected function deserializeEvent($row)
 {
     $metadata = json_decode($row['metadata'], true);
     $payload = json_decode($row['payload'], true);
     return new DomainMessage($row['uuid'], $row['playhead'], $this->metadataSerializer->deserialize($metadata, $metadata['payload']), $this->payloadSerializer->deserialize($payload, $payload['payload']), DateTime::fromString($row['recorded_on']));
 }
 /**
  * @param array $serializedObject
  *
  * @return DomainMessage
  */
 public function deserialize(array $serializedObject)
 {
     return new DomainMessage($serializedObject['id'], $serializedObject['playhead'], $this->metadataSerializer->deserialize($serializedObject['metadata']), $this->payloadSerializer->deserialize($serializedObject['payload']), DateTime::fromString($serializedObject['recordedOn']));
 }