Skip to content

Latest commit

 

History

History
41 lines (34 loc) · 3.18 KB

code_orgnization_for_interservice_communication.md

File metadata and controls

41 lines (34 loc) · 3.18 KB

Code Orgnization for Interservice Communication

Command

Logic

  • Command is more like one service asks another service to do something.
  • Each command channel belongs to a specific service for all the incoming command to that service (each command channel has only one consumer).
  • Multiple services uses their proxy class to send command messages to a specific command channel (each command channel has one or more producer).

Core Classes

Class Description Example
Service Defines the core operations for the service.
  • OrderService
  • Saga Defines the Saga process for a specific operation.
    • Each Saga process consists of multiples steps.
    • Each step consists of a command and the info of which service to execute that command.
  • CreateOrderSaga
  • Commands Handler Defines how to handle each command.
    • Defines mapping relationship between the commands and the command handlers.
    • Each command handler defines the operations need to be executed after receiving a specific command.
  • OrderServiceCommandHandlers
  • Event

    Logic

    • Event is more like one service notifies one or more other services about a change.
    • Aggregate means the core entity of a specific service, like Order entity for the order service, Ticket entity for the kitchen service.
    • One aggregate has one or more events belongs to the aggregate, like TicketCreatedEvent and TicketAcceptedEvent belong to Ticket aggregate.
    • Each event channel belongs to a specific aggregate (each event channel has only one producer).
    • Multiple services may listen to the same event channel (each event channel has one ore more consumer).
    • One event may trigger multiple operations among multiple services simultaneously.

    Core Classes

    Class Description Example
    Service Defines the core operations for the service.
  • KitchenService
  • Domain Event Publisher Publish all the events belongs to a specific aggregate.
  • TicketDomainEventPublisher
  • Event Consumer Defines how to handle each event for a specific aggregate.
    • Defines which aggregate it is listening.
    • Defines mapping relationship between the events and the event handlers.
    • Each event handler defines the operations need to be executed after getting a specific event.
  • KitchenServiceEventConsumer