예제 #1
0
 /**
  * Register the plugin on the workflow environment
  *
  * @param Environment $workflowEnv
  * @return void
  */
 public function registerOn(Environment $workflowEnv)
 {
     $es = $workflowEnv->getEventStore();
     $es->beginTransaction();
     $es->create(new \Prooph\EventStore\Stream\Stream(new \Prooph\EventStore\Stream\StreamName('prooph_processing_stream'), []));
     $es->commit();
 }
예제 #2
0
 /**
  * @param \ZF\Console\Route $route
  * @param ConsoleWriter $consoleWriter
  * @return Environment
  */
 protected function loadEnvironment(Route $route, ConsoleWriter $consoleWriter)
 {
     $configPath = $route->getMatchedParam('config-file', getcwd() . DIRECTORY_SEPARATOR . 'processing.config.php');
     $additionalConfig = $route->getMatchedParam('config', json_encode([]));
     $additionalConfig = json_decode($additionalConfig, true);
     if (is_null($additionalConfig)) {
         $consoleWriter->writeError("Provided config is not a valid json string");
         $consoleWriter->writeError(json_last_error_msg());
         return self::MESSAGE_PROCESSING_FAILED;
     }
     if (file_exists($configPath)) {
         $config = (include $configPath);
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } elseif (file_exists($configPath . '.dist')) {
         $config = (include $configPath . '.dist');
         $consoleWriter->writeInfo('Config loaded from ' . $configPath);
     } else {
         $consoleWriter->writeInfo('No config file specified.');
         if (empty($additionalConfig)) {
             $consoleWriter->writeInfo('Falling back to default config');
         } else {
             $consoleWriter->writeInfo('Using config from argument');
         }
         return $additionalConfig;
     }
     $config = ArrayUtils::merge($config, $additionalConfig);
     $env = Environment::setUp($config);
     $env->getEventStore()->getActionEventDispatcher()->attachListenerAggregate(new PersistedEventsConsoleWriter($consoleWriter));
     return $env;
 }
 /**
  * @test
  */
 public function it_lazy_attaches_plugin_to_configured_channel_of_each_target()
 {
     $env = Environment::setUp(["processing" => ["channels" => ["multi_target_channel" => ["targets" => ["target1", "target2"], "message_dispatcher" => "mocked_message_handler"]]]]);
     $plugin = new SimpleBusPlugin();
     //Preload channels to check if plugin is added to them
     $env->getWorkflowEngine()->getCommandChannelFor("target1");
     $env->getWorkflowEngine()->getEventChannelFor("target1");
     $env->getWorkflowEngine()->attachPluginToAllChannels($plugin);
     $this->assertEquals(2, $plugin->getAttachCount());
     //Request channels again to check that plugin is not attached twice
     $env->getWorkflowEngine()->getCommandChannelFor("target1");
     $env->getWorkflowEngine()->getEventChannelFor("target1");
     $this->assertEquals(2, $plugin->getAttachCount());
     //Load next channels to check if plugin is attached to them, too
     $env->getWorkflowEngine()->getCommandChannelFor("target2");
     $env->getWorkflowEngine()->getEventChannelFor("target2");
     $this->assertEquals(4, $plugin->getAttachCount());
 }
 /**
  * Register the plugin on the workflow environment
  *
  * @param Environment $workflowEnv
  * @return void
  */
 public function registerOn(Environment $workflowEnv)
 {
     $workflowEnv->getWorkflowEngine()->attachPluginToAllChannels($this);
 }
예제 #5
0
 /**
  * @test
  */
 public function it_returns_a_ready_to_use_workflow_processor()
 {
     $env = Environment::setUp();
     $this->assertInstanceOf('Prooph\\Processing\\Processor\\WorkflowProcessor', $env->getWorkflowProcessor());
 }
 /**
  * Register the plugin on the workflow environment
  *
  * @param Environment $workflowEnv
  * @return void
  */
 public function registerOn(Environment $workflowEnv)
 {
     $workflowEnv->getWorkflowProcessor()->events()->attachListener('process_was_started_by_message', [$this, 'onProcessWasStartedByMessage']);
     $workflowEnv->getWorkflowProcessor()->events()->attachListener('process_did_finish', [$this, 'onProcessDidFinish']);
     $workflowEnv->getEventStore()->getActionEventDispatcher()->attachListener('commit.post', [$this, 'onEventStorePostCommit']);
 }
예제 #7
0
 /**
  * @param ConfigLocation $configLocation
  * @return \Prooph\Link\Application\Projection\ProcessingConfig
  */
 public static function asProjectionFrom(ConfigLocation $configLocation)
 {
     if (file_exists($configLocation->toString() . DIRECTORY_SEPARATOR . self::$configFileName)) {
         $instance = self::initializeFromConfigLocation($configLocation);
         return new \Prooph\Link\Application\Projection\ProcessingConfig($instance->toArray(), $configLocation, true);
     } else {
         $env = Environment::setUp();
         return new \Prooph\Link\Application\Projection\ProcessingConfig(['processing' => $env->getConfig()->toArray()], $configLocation);
     }
 }
예제 #8
0
 /**
  * @param Environment $env
  * @param string $address
  * @throws \InvalidArgumentException
  * @return \Codeliner\ArrayReader\ArrayReader
  */
 private function getChannelConfigFor(Environment $env, $address)
 {
     $addressParts = explode(AbstractChannelFactory::CHANNEL_NAME_DELIMITER, $address);
     $target = $addressParts[0];
     $origin = null;
     $sender = null;
     $partsCount = count($addressParts);
     if ($partsCount == 2) {
         $origin = $addressParts[1];
         $sender = $addressParts[1];
     } elseif ($partsCount == 3) {
         $origin = $addressParts[1];
         $sender = $addressParts[2];
     } elseif ($partsCount > 3) {
         throw new \InvalidArgumentException("Address part of channel name is invalid. Address can not be split into valid parts: " . $address);
     }
     $matchForTarget = null;
     $matchForTargetAndOrigin = null;
     $matchForTargetAndSender = null;
     foreach ($env->getConfig()->arrayValue('channels') as $channelConfig) {
         if (!is_array($channelConfig) || !array_key_exists('targets', $channelConfig) || !is_array($channelConfig['targets']) || !in_array($target, $channelConfig['targets']) && !in_array('*', $channelConfig['targets'])) {
             continue;
         }
         $originShouldMatch = isset($channelConfig['origin']);
         $originDidMatch = false;
         $senderShouldMatch = isset($channelConfig['sender']);
         $senderDidMatch = false;
         if ($originShouldMatch) {
             $originDidMatch = $origin && $origin === $channelConfig['origin'];
         }
         if ($senderShouldMatch) {
             $senderDidMatch = $sender && $sender === $channelConfig['sender'];
         }
         if ($originShouldMatch && $senderShouldMatch) {
             if ($originDidMatch && $senderDidMatch) {
                 //All criteria match, so we can stop and return config
                 return new ArrayReader($channelConfig);
             }
             continue;
         }
         if ($originShouldMatch) {
             if ($originDidMatch) {
                 $matchForTargetAndOrigin = $channelConfig;
             }
             continue;
         }
         if ($senderShouldMatch) {
             if ($senderDidMatch) {
                 $matchForTargetAndSender = $channelConfig;
             }
             continue;
         }
         //Origin and sender criteria was not set for this channel config, so we can
         //memorize it for the target, if other channels don't have a better match
         $matchForTarget = $channelConfig;
     }
     //Not all criteria matched, so we need to check how good the matching was
     if ($matchForTargetAndOrigin) {
         return new ArrayReader($matchForTargetAndOrigin);
     }
     if ($matchForTargetAndSender) {
         return new ArrayReader($matchForTargetAndSender);
     }
     if ($matchForTarget) {
         return new ArrayReader($matchForTarget);
     }
     //The local channel is the default one, so if we did not find a channel for an address we assume that the target is locally available
     return new ArrayReader($env->getConfig()->arrayValue('channels.local'));
 }
 /**
  * Register the plugin on the workflow environment
  *
  * @param Environment $workflowEnv
  * @return void
  */
 public function registerOn(Environment $workflowEnv)
 {
     $workflowEnv->getWorkflowProcessor()->events()->attachListener("process_was_started_by_message", [$this, "onProcessWasStartedByMessage"]);
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     return Environment::setUp($serviceLocator);
 }
 /**
  * @test
  */
 public function it_selects_the_target_and_sender_channel_because_target_list_contains_wildcard()
 {
     $targetChannelPlugin = new TargetChannelPlugin();
     $targetAndOriginPlugin = new TargetAndOriginChannelPlugin();
     $targetAndSenderPlugin = new TargetAndSenderChannelPlugin();
     $targetOriginAndSenderPlugin = new TargetOriginAndSenderChannelPlugin();
     $serviceLocator = new ServiceManager();
     $serviceLocator->setService('target_channel_plugin', $targetChannelPlugin);
     $serviceLocator->setService('target_and_origin_channel_plugin', $targetAndOriginPlugin);
     $serviceLocator->setService('target_and_sender_channel_plugin', $targetAndSenderPlugin);
     $serviceLocator->setService('target_origin_and_sender_channel_plugin', $targetOriginAndSenderPlugin);
     $serviceLocator->setService('configuration', ['processing' => ['channels' => ['target_channel' => ['targets' => ['another_target'], 'utils' => ['target_channel_plugin']], 'target_and_origin_channel' => ['targets' => ['another_target'], 'origin' => 'my_origin', 'utils' => ['target_and_origin_channel_plugin']], 'target_and_sender_channel' => ['targets' => ['*'], 'sender' => 'my_sender', 'utils' => ['target_and_sender_channel_plugin']], 'target_origin_and_sender_channel' => ['targets' => ['another_target'], 'origin' => 'my_origin', 'sender' => 'my_sender', 'utils' => ['target_origin_and_sender_channel_plugin']]]]]);
     $env = Environment::setUp($serviceLocator);
     $channel = $env->services()->get('processing.command_bus.my_target___my_origin___my_sender');
     $this->assertInstanceOf(\Prooph\ServiceBus\CommandBus::class, $channel);
     $this->assertFalse($targetAndOriginPlugin->isRegistered());
     $this->assertTrue($targetAndSenderPlugin->isRegistered());
     $this->assertFalse($targetChannelPlugin->isRegistered());
     $this->assertFalse($targetOriginAndSenderPlugin->isRegistered());
 }