/** * 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)); }
/** * @return string */ public function getName() { return $this->proophMessage->messageName(); }
/** * @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())); }