Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Buses

 Buses

Command buses and Event buses

Magnus Nordlander

October 19, 2015
Tweet

More Decks by Magnus Nordlander

Other Decks in Programming

Transcript

  1. The three degrees of doing • Do it yourself •

    Ask someone else to do it • Command it be done
  2. Commands • A command is a message which is imperative

    in nature • ChangeUserPassword • SendWelcomeEmail
  3. Commands • Always handled by exactly one handler • Task-oriented

    • Never returns a value • Required for Command/Query Separation
  4. Command handlers • Immutable services • Handles exactly one command

    type each • Only performs the "primary" task related to the event • Remember SRP and OCP
  5. Why? • Models changes in domain language, capturing intent •

    ChangePassword vs UpdateUser • Maps very well to a Task oriented UI
  6. Why? • Reinforces Command-Query Responsibility Separation (CQRS) • Asking a

    question should not change the answer • Clearly indicates which code changes system state
  7. Events • Events are messages which are informational in nature

    • UserPasswordWasChanged • WelcomeEmailWasSent
  8. Events • Handled by zero or more listeners • Always

    after-the-fact • Cannot change what has already happened
  9. Event listener • Immutable service • Acts upon one type

    of event and performs some action • Should be called every time a pertinent event is handled • No listener should be able to stop propagation
  10. Event bus libs • SimpleBus • Broadway • Symfony EventDispatcher

    • Laravel EventDispatcher • League EventEmitter
  11. Learning more • Matthias Noback has a series of excellent

    blog posts • http://php-and-symfony.matthiasnoback.nl/tags/ command%20bus/ • Also has a Hexagonal Symfony workshop