/**
  * @param Message $message
  * @return array
  */
 private function arrayFromMessage(Message $message)
 {
     $messageData = $this->messageConverter->convertToArray($message);
     MessageDataAssertion::assert($messageData);
     $messageData['created_at'] = $message->createdAt()->format('Y-m-d\\TH:i:s.u');
     return $messageData;
 }
 /**
  * @test
  */
 public function it_will_use_message_converter_for_domain_messages()
 {
     $message = $this->prophesize(DomainMessage::class);
     $this->messageConverter->convertToArray($message)->willReturn(['abc' => '123']);
     $response = $this->SUT->serializeCommand($message->reveal());
     $this->assertArrayHasKey('data', $response);
     $this->assertArrayHasKey('abc', $response['data']);
 }
 /**
  * @param mixed $command
  * @return array
  */
 public function serializeCommand($command)
 {
     $data = [];
     if ($command instanceof DomainMessage) {
         $data = $this->messageConverter->convertToArray($command);
     }
     if (is_object($command)) {
         $command = get_class($command);
     }
     return ['command' => $command, 'data' => $data, 'meta' => $this->meta];
 }
 /**
  * @param  Envelope $envelope
  * @throws InvalidArgumentException
  * @return string
  */
 public function serialize(Envelope $envelope)
 {
     $message = $envelope->getMessage();
     if (!$message instanceof BernardMessage) {
         throw new InvalidArgumentException(sprintf("Serialize message %s failed due to wrong message type", $message->getName()));
     }
     $messageData = $this->messageConverter->convertToArray($message->getProophMessage());
     MessageDataAssertion::assert($messageData);
     $messageData['created_at'] = $message->getProophMessage()->createdAt()->format('Y-m-d\\TH:i:s.u');
     return json_encode(['message' => $messageData, 'timestamp' => $envelope->getTimestamp()]);
 }
 /**
  * @inheritdoc
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     $messageData = $this->messageConverter->convertToArray($message);
     MessageDataAssertion::assert($messageData);
     $messageData['created_at'] = $message->createdAt()->format('Y-m-d\\TH:i:s.u');
     $promise = $this->guzzleClient->postAsync($this->uri, ['json' => $messageData]);
     if ($deferred) {
         if ($this->async) {
             $this->resolveOrRejectDeferredAsync($deferred, $promise);
         } else {
             $this->resolveOrRejectDeferredSync($deferred, $promise);
         }
     }
 }
 /**
  * @param Message $event
  *
  * @return Document
  */
 private function convertEventToDocument(Message $event)
 {
     $eventArr = $this->messageConverter->convertToArray($event);
     MessageDataAssertion::assert($eventArr);
     $data = ['event_id' => $eventArr['uuid'], 'version' => $eventArr['version'], 'event_name' => $eventArr['message_name'], 'payload' => $eventArr['payload'], 'metadata' => $eventArr['metadata'], 'created_at' => $eventArr['created_at']->format('Y-m-d\\TH:i:s.u')];
     $document = new Document($data);
     $document->setId($data['event_id']);
     return $document;
 }
 /**
  * Insert an event
  *
  * @param StreamName $streamName
  * @param Message $e
  * @return void
  */
 private function insertEvent(StreamName $streamName, Message $e)
 {
     $eventArr = $this->messageConverter->convertToArray($e);
     MessageDataAssertion::assert($eventArr);
     $eventData = ['event_id' => $eventArr['uuid'], 'version' => $eventArr['version'], 'event_name' => $eventArr['message_name'], 'payload' => $this->payloadSerializer->serializePayload($eventArr['payload']), 'created_at' => $eventArr['created_at']->format('Y-m-d\\TH:i:s.u')];
     foreach ($eventArr['metadata'] as $key => $value) {
         $eventData[$key] = (string) $value;
     }
     $this->connection->insert($this->getTable($streamName), $eventData);
 }
 /**
  * @param StreamName $streamName
  * @param Message $e
  * @return array
  */
 private function prepareEventData(StreamName $streamName, Message $e)
 {
     $eventArr = $this->messageConverter->convertToArray($e);
     $eventData = ['_id' => $eventArr['uuid'], 'version' => $eventArr['version'], 'event_name' => $eventArr['message_name'], 'payload' => $eventArr['payload'], 'created_at' => $eventArr['created_at']->format('Y-m-d\\TH:i:s.u')];
     foreach ($eventArr['metadata'] as $key => $value) {
         $eventData[$key] = (string) $value;
     }
     if (null !== $this->transactionId) {
         $eventData['transaction_id'] = $this->transactionId;
         $eventData['expire_at'] = new \MongoDate();
     }
     return $eventData;
 }
Exemple #9
0
 /**
  * @param ChapterStatus $chapterStatus
  * @param ChapterTemplate $chapterTemplate
  * @param Message $receivedMessage
  * @param MessageConverter $messageConverter
  * @param MessageFactory $messageFactory
  * @param StoryName $storyName
  */
 private function handleFailedChapter(ChapterStatus $chapterStatus, ChapterTemplate $chapterTemplate, Message $receivedMessage, MessageConverter $messageConverter, MessageFactory $messageFactory, StoryName $storyName)
 {
     $failedStatus = $chapterStatus->markChapterAsFailed();
     $this->recordThat(ChapterFailed::withStatusByMessage($failedStatus, $messageConverter->convertToArray($receivedMessage)));
     if ($failedStatus->isRetryPossible()) {
         $retryStatus = $failedStatus->retry();
         $startMessage = $this->getOriginalStartMessageForChapterNumber($retryStatus->chapterNumber(), $messageFactory);
         $chapterCommand = $chapterTemplate->startChapter($storyName, $retryStatus->chapterNumber(), $startMessage);
         $this->recordThat(ChapterRetryWasStarted::withStatusByMessage($retryStatus, $messageConverter->convertToArray($chapterCommand)));
         $this->nextCommands[] = $chapterCommand;
         return;
     }
     $this->recordThat(StoryFailed::withStoryIdAndName($failedStatus->chapterNumber()->storyId(), $storyName));
 }