/** * @param RemoteMessage $message * @return LogMessage|WorkflowMessage|StartSubProcess|SubProcessFinished * @throws \InvalidArgumentException */ public function translateToProcessingMessage(RemoteMessage $message) { if (MessageNameUtils::isWorkflowMessage($message->name())) { return WorkflowMessage::fromServiceBusMessage($message); } else { if (MessageNameUtils::isProcessingLogMessage($message->name())) { return LogMessage::fromServiceBusMessage($message); } else { if (StartSubProcess::MSG_NAME === $message->name()) { return StartSubProcess::fromServiceBusMessage($message); } else { if (SubProcessFinished::MSG_NAME === $message->name()) { return SubProcessFinished::fromServiceBusMessage($message); } } } } throw new \InvalidArgumentException(sprintf('Message with name %s can not be translated. Unknown type provided.', $message->name())); }
/** * @return WorkflowMessage|LogMessage * @throws \RuntimeException */ public function lastMessage() { $sbMessage = RemoteMessage::fromArray($this->payload['last_message']); if (MessageNameUtils::isProcessingLogMessage($sbMessage->name())) { return LogMessage::fromServiceBusMessage($sbMessage); } if (MessageNameUtils::isWorkflowMessage($sbMessage->name())) { return WorkflowMessage::fromServiceBusMessage($sbMessage); } throw new \RuntimeException(sprintf("Sub process %s has received last a message with name %s that has no known message format", $this->processorNodeName() . '::' . $this->subProcessId(), $sbMessage->name())); }
/** * @return null|WorkflowMessage */ public function previousWorkflowMessage() { if ($this->payload['previous_message']) { $sbMessage = RemoteMessage::fromArray($this->payload['previous_message']); return WorkflowMessage::fromServiceBusMessage($sbMessage); } return null; }
/** * @test */ public function it_translates_itself_to_service_bus_message_and_back() { $wfMessage = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName()->toString(), array('metadata' => true)); $sbMessage = $wfMessage->toServiceBusMessage(); $this->assertInstanceOf('Prooph\\Common\\Messaging\\RemoteMessage', $sbMessage); $copyOfWfMessage = WorkflowMessage::fromServiceBusMessage($sbMessage); $this->assertInstanceOf('Prooph\\Processing\\Message\\WorkflowMessage', $copyOfWfMessage); $this->assertEquals(MessageNameUtils::MESSAGE_NAME_PREFIX . 'proophprocessingtestmockuserdictionary-collect-data', $copyOfWfMessage->messageName()); $this->assertNull($copyOfWfMessage->payload()->extractTypeData()); $this->assertEquals(array('metadata' => true), $copyOfWfMessage->metadata()); $this->assertEquals(MessageNameUtils::COLLECT_DATA, $copyOfWfMessage->messageType()); $this->assertEquals('test-case', $copyOfWfMessage->origin()); $this->assertEquals(NodeName::defaultName()->toString(), $copyOfWfMessage->target()); }