Anton Sidorov homepage

Bookmark this to keep an eye on my project updates!

Follow me on GitHub

Command Bus

Зачем

Используется совместно с паттерном Command

  • используется для выполнения команд (Command): создание объекта, отправка электронной почты и т.д.
  • В этом случае, компоненты ИС выступают в роли отправителей команд, а другие компоненты - в роли получателей и исполнителей этих команд
  • отслеживать состояние выполнения команды и сообщать об ошибке, если такая произошла (Job Manager)
  • The Command bus matches commands to handlers. This matching can be done automatically by some kind of naming convention. Another option is to register the relationships on the command bus.
    • Ensure the transport of a Command to its Handler. The Command Bus receives a Command, which is nothing more than a message describing intent, and passes this onto a Handler which is then responsible for performing the expected behavior.
  • The standard interface also makes it possible for additional functionality to be added by wrapping with decorators, or by adding middleware. middleware
  • TODO:

Differences Event Bus

  • While commands have exactly one corresponding command handler, there is a one-to-many correspondence between an event and its handlers. There may even be zero handlers for a particular event.
  • Events are not (supposed to be) handled in a separate database transaction, like commands are.
  • Event Bus используется для передачи событий (event) между компонентами системы. В этом случае, компоненты генерируют события, а другие компоненты слушают эти события и реагируют на них соответствующим образом.
  • основное отличие - в типе сообщений