Class: Yes::Core::CommandHandling::EventPublisher

Inherits:
Object
  • Object
show all
Includes:
OpenTelemetry::Trackable
Defined in:
lib/yes/core/command_handling/event_publisher.rb

Overview

Handles publishing events with revision checks

Defined Under Namespace

Classes: AggregateEventPublicationData

Instance Method Summary collapse

Constructor Details

#initialize(command:, aggregate_data:, accessed_external_aggregates:, event_name: nil) ⇒ EventPublisher

Returns a new instance of EventPublisher.

Parameters:

  • command (Object)

    The command instance

  • aggregate_data (AggregateEventPublicationData)

    The aggregate publication data

  • accessed_external_aggregates (Array<Hash>)

    List of accessed external aggregates with their revisions

  • event_name (String, nil) (defaults to: nil)

    Optional explicit event name to use



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yes/core/command_handling/event_publisher.rb', line 39

def initialize(command:, aggregate_data:, accessed_external_aggregates:, event_name: nil)
  @command = command
  @aggregate_data = aggregate_data
  @accessed_external_aggregates = accessed_external_aggregates
  @event_name = event_name
  @command_utilities = Utils::CommandUtils.new(
    context: aggregate_data.context,
    aggregate: aggregate_data.name,
    aggregate_id: aggregate_data.id
  )
end

Instance Method Details

#callPgEventstore::Event

Publishes the event after verifying revisions

Returns:

  • (PgEventstore::Event)

    The published event

Raises:

  • (PgEventstore::WrongExpectedRevisionError)

    When revisions don’t match



55
56
57
58
# File 'lib/yes/core/command_handling/event_publisher.rb', line 55

def call
  verify_external_revisions!
  publish_event
end