/**
  * {@inheritDoc}
  */
 public function replay($events, $queueName)
 {
     $adapter = $this->queueFactory->create($queueName);
     foreach ($events as $domainMessage) {
         $msg = json_encode($this->serializer->serialize($domainMessage));
         $adapter->publish($msg);
     }
     $adapter->publish('finished');
 }
 /**
  * @param ReadModelInterface $data
  *
  * @return mixed
  */
 public function save(ReadModelInterface $data)
 {
     $id = $data->getId();
     $payload = $this->serializer->serialize($data);
     $payload['id'] = $id;
     $item = $this->find($id);
     if ($item) {
         $this->newQuery()->replaceOne(['id' => $id], $payload);
     } else {
         $this->newQuery()->insertOne($payload);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function dispatch($command)
 {
     $this->init();
     if (!is_object($command)) {
         throw new CommandNotAnObjectException();
     }
     $serializedCommand = json_encode($this->serializer->serialize($command));
     $this->response = null;
     $this->corr_id = uniqid();
     $msg = new AMQPMessage((string) $serializedCommand, array('correlation_id' => $this->corr_id, 'reply_to' => $this->callback_queue));
     $this->channel->basic_publish($msg, self::EXCHANGE_NAME, 'command');
     while (!$this->response) {
         $this->channel->wait(null, false, 10);
     }
     $this->channel->close();
     return $this->response;
 }
 /**
  * serialize some property to json
  */
 private function serialize($property)
 {
     return json_encode($this->serializer->serialize($property));
 }
 public function save(ReadModelInterface $data)
 {
     $this->connection->delete(static::TABLE, ['class' => $this->class, 'id' => $data->getId()]);
     $this->connection->insert(static::TABLE, ['class' => $this->class, 'id' => $data->getId(), 'serialized' => json_encode($this->serializer->serialize($data))]);
 }
 /**
  * Turns a DomainMessage into array using broadway's serializers.
  *
  * @param DomainMessage $message The domain message.
  * @throws SerializationException When the serializers cannot perform.
  * @return array                  An array representation of the message.
  */
 private function convertDomainMessage(DomainMessage $message)
 {
     $metadata = $this->metadataSerializer->serialize($message->getMetadata());
     $payload = $this->payloadSerializer->serialize($message->getPayload());
     return ['uuid' => (string) $message->getId(), 'playhead' => $message->getPlayhead(), 'metadata' => json_encode($metadata), 'payload' => json_encode($payload), 'recorded_on' => $message->getRecordedOn()->toString(), 'type' => $message->getType()];
 }
 /**
  * @param DomainMessage $object
  * @return array
  */
 public function serialize(DomainMessage $object)
 {
     return ['id' => $object->getId(), 'playhead' => $object->getPlayhead(), 'metadata' => $this->metadataSerializer->serialize($object->getMetadata()), 'payload' => $this->payloadSerializer->serialize($object->getPayload()), 'recordedOn' => $object->getRecordedOn()->toString()];
 }