/** * @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())); }
/** * @param RemoteMessage $aMessage * @return WorkflowMessage * @throws \RuntimeException */ public static function fromServiceBusMessage(RemoteMessage $aMessage) { $payload = $aMessage->payload(); Assertion::keyExists($payload, 'json'); Assertion::keyExists($payload, 'origin'); Assertion::keyExists($payload, 'target'); $origin = $payload['origin']; $target = $payload['target']; $taskListPosition = isset($payload['processTaskListPosition']) ? TaskListPosition::fromString($payload['processTaskListPosition']) : null; $messagePayload = Payload::fromJsonDecodedData(json_decode($payload['json'], true)); $metadata = isset($payload['metadata']) ? $payload['metadata'] : []; return new static($messagePayload, $aMessage->name(), $origin, $target, $metadata, $taskListPosition, $aMessage->header()->version(), $aMessage->header()->createdAt(), $aMessage->header()->uuid()); }
/** * @param LogMessageReceived $event */ protected function whenLogMessageReceived(LogMessageReceived $event) { $taskListEntry = $this->taskList->getTaskListEntryAtPosition($event->taskListPosition()); $sbMessage = RemoteMessage::fromArray($event->payload()['message']); $taskListEntry->logMessage(LogMessage::fromServiceBusMessage($sbMessage)); }
protected function setLogFromArray(array $log) { foreach ($log as $sbMessageArr) { $sbMessage = RemoteMessage::fromArray($sbMessageArr); $this->log[] = LogMessage::fromServiceBusMessage($sbMessage); } }
/** * @return null|WorkflowMessage */ public function previousWorkflowMessage() { if ($this->payload['previous_message']) { $sbMessage = RemoteMessage::fromArray($this->payload['previous_message']); return WorkflowMessage::fromServiceBusMessage($sbMessage); } return null; }
/** * @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())); }
/** * @param RemoteMessage $aMessage * @return LogMessage * @throws \RuntimeException */ public static function fromServiceBusMessage(RemoteMessage $aMessage) { $payload = $aMessage->payload(); Assertion::keyExists($payload, 'processTaskListPosition'); Assertion::keyExists($payload, 'origin'); Assertion::keyExists($payload, 'technicalMsg'); Assertion::keyExists($payload, 'msgParams'); Assertion::keyExists($payload, 'msgCode'); $taskListPosition = TaskListPosition::fromString($payload['processTaskListPosition']); return new self($payload['origin'], $taskListPosition, $payload['technicalMsg'], $payload['msgCode'], $payload['msgParams'], $aMessage->header()->uuid(), $aMessage->header()->createdAt()); }