Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process manager in event-engine #7

Closed
arnedesmedt opened this issue Jun 3, 2019 · 2 comments
Closed

Process manager in event-engine #7

arnedesmedt opened this issue Jun 3, 2019 · 2 comments

Comments

@arnedesmedt
Copy link
Contributor

Hello,

Is it possible to use some sort of process manager for the generated events?

Thx in advance,
Arne

@codeliner
Copy link
Contributor

codeliner commented Jun 3, 2019

Hi,

ProcessManagers listen on events $eventEngine->on(<event_name>, <proces_manager>) like described in the tutorial

If a process manager should dispatch a new command handled by the same app, you can also use a short cut by returning a command from a static method:

final class MyProcessManager
{
  public static function onSomethingHappened(Message $somethingHappened): array
  {
    // Return command tuple (when using PrototypingFlavour or a command instance for other Flavour)
    return [
      Command::DO_SOEMTHING_AFTER_EVENT,
      $somethingHappend->payload(), // Map payload from event to command if needed
      [ /* optional metadata array */ ]
    ];
  }
}

// Register the process manager in a Description using callable array syntax
$eventEngine->on(Event::SOMETHING_HAPPENED, [MyProcessManager::class, 'onSomethingHappened']);

The short cut is not documented yet as this is a relatively new feature. The way shown in the Tutorial is the preferred way when the process manager requires dependencies. With the short cut you avoid the round trip to the DI container which is nice for simple IF THIS THAN THAT scenarios.

@arnedesmedt
Copy link
Contributor Author

Thank you very much for the explanation!

I forgot that their was a process manager subtitle in the tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants