Esempio n. 1
0
 /**
  * Determine the required process type based on given message and the message handler which will receive the message.
  *
  * @param Message $message
  * @param MessageHandler $messageHandler
  * @return ProcessType
  * @throws Workflow\Exception\MessageIsNotManageable
  */
 private function determineProcessType(Message $message, MessageHandler $messageHandler)
 {
     if ($messageHandler->canHandleMessage($message)) {
         if ($message->processingMetadata()->shouldCollectionBeSplitIntoChunks()) {
             $processType = ProcessType::parallelChunk();
         } else {
             $processType = ProcessType::linearMessaging();
         }
     } else {
         //We create the error before trying the foreach alternative to provide the client with the original error message
         //if the alternative fails too.
         $originalError = MessageIsNotManageable::byMessageHandler($messageHandler, $message);
         //Check if we can use a foreach process to avoid the rejection of the message
         if ($this->isForeachProcessPossible($message, $messageHandler)) {
             $processType = ProcessType::parallelForeach();
         } else {
             throw $originalError;
         }
     }
     return $processType;
 }
 /**
  * @param Task $connectedTask
  * @return Message
  * @throws Workflow\Exception\MessageIsNotManageable
  */
 public function emulateAnswerMessage(Task $connectedTask)
 {
     if (!$this->canHandleMessage($connectedTask->emulateWorkflowMessage())) {
         throw MessageIsNotManageable::byMessageHandler($this, $connectedTask->emulateWorkflowMessage());
     }
     if ($connectedTask->type()->isCollectData()) {
         $messageType = MessageType::dataCollected();
     } else {
         $messageType = MessageType::dataProcessed();
     }
     return Message::emulateProcessingWorkflowMessage($messageType, $connectedTask->processingType(), $connectedTask->metadata());
 }