/** * @return Message */ public function startMessage() { $startMessage = $this->payload['start_message']; if (isset($startMessage['metadata'])) { $metadata = ProcessingMetadata::fromArray($startMessage['metadata']); } else { $metadata = ProcessingMetadata::noData(); } $processingType = $startMessage['processing_type']; return Message::emulateProcessingWorkflowMessage(MessageType::fromString($startMessage['message_type']), $processingType::prototype(), $metadata); }
public function create($data) { if (!array_key_exists('name', $data)) { return $this->apiProblem(422, "No name given for the message handler"); } if (!array_key_exists('node_name', $data)) { return $this->apiProblem(422, "No node_name given for the message handler"); } if (!array_key_exists('type', $data)) { return $this->apiProblem(422, "No type given for the message handler"); } if (!array_key_exists('data_direction', $data)) { return $this->apiProblem(422, "No data_direction given for the message handler"); } if (!array_key_exists('metadata_riot_tag', $data)) { return $this->apiProblem(422, "No metadata_riot_tag given for the message handler"); } if (!array_key_exists('icon', $data)) { return $this->apiProblem(422, "No icon given for the message handler"); } if (!array_key_exists('icon_type', $data)) { return $this->apiProblem(422, "No icon_type given for the message handler"); } if (!isset($data['processing_types'])) { $data['processing_types'] = ProcessingTypes::SUPPORT_ALL; } if (!isset($data['processing_metadata'])) { $data['processing_metadata'] = ProcessingMetadata::noData()->toArray(); } if (!isset($data['preferred_type'])) { $data['preferred_type'] = null; } if (!isset($data['processing_id'])) { $data['processing_id'] = null; } if (!isset($data['additional_data'])) { $data['additional_data'] = []; } $messageHandlerId = MessageHandlerId::generate(); $this->commandBus->dispatch(InstallMessageHandler::withData($messageHandlerId, $data['name'], $data['node_name'], $data['type'], $data['data_direction'], $data['processing_types'], $data['processing_metadata'], $data['metadata_riot_tag'], $data['icon'], $data['icon_type'], $data['preferred_type'], $data['processing_id'], $data['additional_data'])); return $this->location($this->url()->fromRoute('prooph.link/process_config/api/message_handler', ['id' => $messageHandlerId->toString()])); }
/** * @test */ function it_installs_a_message_handler() { $messageHandler = ProcessingNode::initializeAs(NodeName::defaultName())->installMessageHandler(MessageHandlerId::generate(), 'Article Exporter', HandlerType::connector(), DataDirection::source(), ProcessingTypes::support([ArticleCollection::prototype()]), ProcessingMetadata::noData(), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', ArticleCollection::prototype(), ProcessingId::fromString('sqlconnector:::example')); $this->assertInstanceOf(MessageHandler::class, $messageHandler); }
/** * @param Task $previousTask * @param MessageHandler $previousMessageHandler * @param MessageHandler $nextMessageHandler * @throws \RuntimeException * @internal param \Prooph\Link\ProcessManager\Model\Workflow\Message $lastAnswer * @return Task[] */ public function determineNextTasks(Task $previousTask, MessageHandler $previousMessageHandler, MessageHandler $nextMessageHandler) { $tasks = []; $taskMetadata = ProcessingMetadata::noData(); $lastAnswer = $previousMessageHandler->emulateAnswerMessage($previousTask); //@TODO: Implement sub process set up if (!$this->processingNodeName()->equals($nextMessageHandler->processingNodeName())) { throw new \RuntimeException("Running message handler on different nodes is not supported yet!"); } $task = $this->scheduleTaskFor($nextMessageHandler, $taskMetadata, $lastAnswer); $nextMessage = $task->emulateWorkflowMessage(); $processType = $this->determineProcessType($nextMessage, $nextMessageHandler); $previousTaskProcess = $this->getProcessOfTask($previousTask); if (is_null($previousTaskProcess)) { throw TaskProcessNotFound::of($previousTask, $this); } if (!$previousTaskProcess->type()->isLinearMessaging() || !$processType->isLinearMessaging()) { //@TODO: Implement sub process handling throw new \RuntimeException("Handling follow up tasks with a process type other than linear messaging is not supported yet!"); } $this->recordThat(TaskWasAddedToProcess::record($this->workflowId(), $previousTaskProcess, $task)); $tasks[] = $task; return $tasks; }
function provideStartScenarios() { return [[Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK]]; }
/** * @param $dataDirection * @param null|string $handlerType * @param null|array $metadata * @return MessageHandler */ private function getMessageHandler($dataDirection, $handlerType = null, array $metadata = null) { if (!is_null($handlerType)) { $handlerType = MessageHandler\HandlerType::fromString($handlerType); } else { $handlerType = MessageHandler\HandlerType::connector(); } if (!is_null($metadata)) { $metadata = ProcessingMetadata::fromArray($metadata); } else { $metadata = ProcessingMetadata::noData(); } return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Export', NodeName::defaultName(), $handlerType, MessageHandler\DataDirection::fromString($dataDirection), MessageHandler\ProcessingTypes::support([ArticleCollection::prototype(), Article::prototype()]), $metadata, 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', Article::prototype(), MessageHandler\ProcessingId::fromString('sqlconnector:::example')); }