Example #1
0
 /**
  * @return string
  */
 public function messageName()
 {
     switch ($this->messageType()->toString()) {
         case MessageType::TYPE_DATA_PROCESSED:
             return MessageNameUtils::getDataProcessedEventName($this->processingType()->of());
         case MessageType::TYPE_PROCESS_DATA:
             return MessageNameUtils::getProcessDataCommandName($this->processingType()->of());
         case MessageType::TYPE_DATA_COLLECTED:
             return MessageNameUtils::getDataCollectedEventName($this->processingType()->of());
         case MessageType::TYPE_COLLECT_DATA:
             return MessageNameUtils::getCollectDataCommandName($this->processingType()->of());
     }
 }
Example #2
0
/**
 * This function returns a ready to use Prooph\Processing\Processor\WorkflowProcessor
 *
 * A workflow in processing is the definition of a process. Each Process contains
 * a task list. And each task on the list describes a single action that should be done.
 * The workflow processor manages running processes and logs their progress and status.
 * Processing makes use of a technique performed event sourcing. The model is based on events
 * which are persisted in a stream and used to reconstitute the model for further processing.
 *
 * @return \Prooph\Processing\Processor\WorkflowProcessor
 */
function set_up_workflow_environment()
{
    //A process definition is a configuration based on a php array
    //We define a linear messaging process here ...
    $processDefinition = ["process_type" => \Prooph\Processing\Processor\Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [["task_type" => \Prooph\Processing\Processor\Definition::TASK_PROCESS_DATA, "target" => "target-file-writer", "allowed_types" => ['Prooph\\ProcessingExample\\Type\\SourceUser']]]];
    //... and map it to the name of the initial workflow message which will trigger the process
    //The process factory is capable of parsing a process definition and build a process object from it
    //which can be processed by a workflow processor
    $processFactory = new \Prooph\Processing\Processor\ProcessFactory([\Prooph\Processing\Message\MessageNameUtils::getDataCollectedEventName('Prooph\\ProcessingExample\\Type\\SourceUser') => $processDefinition]);
    //Here we set up the processor dependencies. Don't worry!
    //When you set up your own workflow system Prooph\Processing\Environment will
    //do the heavy lifting for you. We don't use it here cause you should
    //get an idea of the internal structure.
    //It's always a good thing to know the internals of a system not only the public API.
    //See comments in the set up functions to get more information about the individual components
    $eventStore = _set_up_event_store();
    $workflowEngine = _set_up_workflow_engine();
    $processRepository = new \Prooph\Processing\Processor\ProcessRepository($eventStore);
    //We need to create an empty stream for our process events.
    //The example uses in memory persistence
    //so we need to create the stream each time the script is running.
    //A production system should have a set up script and make use of a persistent adapter
    //available for ProophEventStore
    $eventStore->beginTransaction();
    $eventStore->create(new \Prooph\EventStore\Stream\Stream(new \Prooph\EventStore\Stream\StreamName('prooph_processing_stream'), []));
    $eventStore->commit();
    /**
     * Summary of what we've learned:
     * The WorkflowProcessor is a so performed process manager. It triggers and receives messages with the help of
     * a WorkflowEngine, starts and updates processes and manages the persistence of recorded process events with the
     * help of an EventStore and a ProcessRepository.
     * New processes are derived from a ProcessFactory which is capable of parsing process definitions and set up
     * processes with a TaskList.
     * The node name provided as first argument identifies the system which runs the processor. For local processing
     * it is enough to use the default node name defined in the definition class but when working with
     * many processing nodes you should give each node a unique name and configure the workflow engine to
     * provide the correct bus for each node.
     */
    $workflowProcessor = new \Prooph\Processing\Processor\WorkflowProcessor(\Prooph\Processing\Processor\NodeName::defaultName(), $eventStore, $processRepository, $workflowEngine, $processFactory);
    $eventBus = $workflowEngine->getEventChannelFor(\Prooph\Processing\Processor\Definition::SERVICE_WORKFLOW_PROCESSOR);
    //Processing provides a special ProophServiceBus plugin that can route all incoming messages to a single target
    //in this case we want to route every message to the workflow processor
    //Prooph\Processing\Environment attaches such a router to each service bus
    $eventBus->utilize(new \Prooph\Processing\Processor\ProophPlugin\SingleTargetMessageRouter($workflowProcessor));
    //Prooph\Processing also provides a special invoke strategy for the workflow processor
    $eventBus->utilize(new \Prooph\Processing\Processor\ProophPlugin\WorkflowProcessorInvokeStrategy());
    return $workflowProcessor;
}
Example #3
0
 /**
  * Transforms current message to a data collected event and replaces payload data with collected data
  *
  * @param Type $collectedData
  * @param array $metadata
  * @throws \Prooph\Processing\Type\Exception\InvalidTypeException If answer type does not match with the previous requested type
  * @return WorkflowMessage
  */
 public function answerWith(Type $collectedData, array $metadata = [])
 {
     $collectedPayload = Payload::fromType($collectedData);
     $collectedDataTypeClass = $collectedPayload->getTypeClass();
     if ($this->payload->getTypeClass() !== $collectedPayload->getTypeClass()) {
         throw InvalidTypeException::fromInvalidArgumentExceptionAndPrototype(new \InvalidArgumentException(sprintf("Type %s of collected data does not match the type of requested data %s", $collectedPayload->getTypeClass(), $this->payload->getTypeClass())), $collectedDataTypeClass::prototype());
     }
     $type = MessageNameUtils::getTypePartOfMessageName($this->messageName);
     $metadata = ArrayUtils::merge($this->metadata, $metadata);
     return new self($collectedPayload, MessageNameUtils::getDataCollectedEventName($type), $this->target, $this->origin, $metadata, $this->processTaskListPosition, $this->version + 1);
 }
 /**
  * @test
  */
 public function it_returns_a_data_collected_event_name_including_the_type_class_normalized()
 {
     $eventName = MessageNameUtils::getDataCollectedEventName('Prooph\\ProcessingTest\\Mock\\UserDictionary');
     $this->assertEquals(MessageNameUtils::MESSAGE_NAME_PREFIX . 'proophprocessingtestmockuserdictionary-data-collected', $eventName);
 }