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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/yes/core/command_handling/event_publisher.rb', line 46

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

#call ⇒ PgEventstore::Event

Publishes the event after verifying revisions

Returns:

  • (PgEventstore::Event) —

    The published event

Raises:

  • (PgEventstore::WrongExpectedRevisionError) —

    When revisions don't match



62
63
64
65
# File 'lib/yes/core/command_handling/event_publisher.rb', line 62

def call
  verify_external_revisions!
  publish_event
end