Пример #1
0
 /**
  * @param Message $message
  * @return bool
  */
 public function isTrueFor(Message $message)
 {
     if ($message instanceof Info) {
         $payload = $message->payload();
         if (isset($payload['context']['success'])) {
             return $payload['context']['success'];
         }
     }
     return false;
 }
Пример #2
0
 /**
  * @param StoryName $storyName
  * @param Message $startMessage
  * @param ChapterTemplate[] $chapterTemplates
  * @param MessageConverter $messageConverter
  * @throws Exception\Story
  * @return Story
  */
 public static function start(StoryName $storyName, Message $startMessage, array $chapterTemplates, MessageConverter $messageConverter)
 {
     self::assertChapterTemplates($chapterTemplates, $storyName);
     $storyId = StoryId::fromString($startMessage->uuid()->toString());
     $self = new self();
     $self->recordThat(StoryWasStarted::withStoryIdAndName($storyId, $storyName));
     $nextCommands = $self->startNextChapters($storyName, $startMessage, $chapterTemplates, $storyId, $messageConverter);
     if (empty($nextCommands)) {
         throw Exception\Story::cannotBeStartedForMessage($startMessage);
     }
     $self->nextCommands = $nextCommands;
     return $self;
 }
 /**
  * Resolves the deferred for a given message.
  * If an error occurs, the deferred is rejected and a reason will be given.
  *
  * If a message is parallel message (instance of \Prooph\ServiceBus\Message\HumusAmqp\ParallelMessage)
  * and instance of \Humus\Amqp\JsonRpc\JsonRpcResponseCollection, which can be queried for given
  * message ids.
  *
  * @param Message $message
  * @param Deferred|null $deferred
  * @throws RuntimeException If a $deferred is not passed
  * @return void
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     if (null === $deferred) {
         throw new RuntimeException('Deferred expected, null given');
     }
     if ($message instanceof ParallelMessage) {
         foreach ($message->messages() as $parallelMessage) {
             $data = $this->arrayFromMessage($parallelMessage);
             $this->client->addRequest(new JsonRpcRequest('server', $message->messageName(), $data, $message->uuid()->toString(), $message->messageName(), 0, $message->createdAt()->getTimestamp()));
         }
     } else {
         $data = $this->arrayFromMessage($message);
         $messageId = $message->uuid()->toString();
         $this->client->addRequest(new JsonRpcRequest('server', $message->messageName(), $data, $messageId, $message->messageName(), 0, $message->createdAt()->getTimestamp()));
         $results = $this->client->getResponseCollection($this->timeout);
         if ($results instanceof Error) {
             $deferred->reject($results->message());
         }
         $response = $results->getResponse($messageId);
         $deferred->resolve($response->result());
     }
     $deferred->resolve($this->client->getResponseCollection($this->timeout));
 }
Пример #4
0
 /**
  * @param Message $message
  * @return bool
  */
 private function isStartMessage(Message $message)
 {
     return !isset($message->metadata()[Metadata::STORY_CHAPTER]);
 }
Пример #5
0
 /**
  * @param Message $streamEvent
  * @param array $metadata
  * @return bool
  */
 protected function matchMetadataWith(Message $streamEvent, array $metadata)
 {
     if (empty($metadata)) {
         return true;
     }
     $streamEventMetadata = $streamEvent->metadata();
     foreach ($metadata as $key => $value) {
         if (!isset($streamEventMetadata[$key])) {
             return false;
         }
         if ($streamEventMetadata[$key] !== $value) {
             return false;
         }
     }
     return true;
 }
 /**
  * @return string
  */
 public function getName()
 {
     return $this->proophMessage->messageName();
 }
Пример #7
0
 /**
  * @param Message $message
  * @param StoryId $ownStoryId
  * @param StoryId $otherStoryId
  * @return Story
  */
 public static function receivedMessageForDifferentStory(Message $message, StoryId $ownStoryId, StoryId $otherStoryId)
 {
     return new self(sprintf('Story %s received message %s (%s) for different story %s', $ownStoryId->toString(), $message->messageName(), $message->uuid()->toString(), $otherStoryId->toString()));
 }