/** * {@inheritdoc} */ public function send($routingKey, CommandMessageInterface $command, CommandCallbackInterface $callback = null) { $destination = $this->template->getRoutingDestination($command->getCommandName(), $routingKey); if (null === $destination) { $destination = $this->findSuitableNode($command); $this->template->setRoutingDestination($destination, $command->getCommandName(), $routingKey); } // dispatch locally if destination matches this node if ($this->template->getNodeName() === $destination) { $this->localSegment->dispatch($command, $callback); return; } $awaitReply = $callback ? true : false; $dispatchMessage = new DispatchMessage($command, $this->serializer, $awaitReply); $this->template->enqueueCommand($destination, $dispatchMessage->toBytes()); if ($awaitReply) { $reply = $this->template->readCommandReply($command->getIdentifier()); if (null === $reply) { $callback->onFailure(new CommandTimeoutException($command->getIdentifier())); return; } $replyMessage = ReplyMessage::fromBytes($this->serializer, $reply[1]); if ($replyMessage->isSuccess()) { $callback->onSuccess($replyMessage->getReturnValue()); } else { $callback->onFailure(new CommandDispatchException($replyMessage->getError())); } } }
public function testExceptionResult() { $serializer = new JMSSerializer(); $replyMessage1 = new ReplyMessage(self::COMMAND_ID, $serializer, new \RuntimeException("Exception !!!"), false); $bytes = $replyMessage1->toBytes(); $replyMessage2 = ReplyMessage::fromBytes($serializer, $bytes); $this->assertEquals($replyMessage1->getReturnValue(), $replyMessage2->getReturnValue()); $this->assertEquals($replyMessage1->getError(), $replyMessage2->getError()); $this->assertEquals($replyMessage1->getCommandIdentifier(), $replyMessage2->getCommandIdentifier()); $this->assertFalse($replyMessage1->isSuccess()); $this->assertFalse($replyMessage2->isSuccess()); }