Class: Mammoth::ReplicationConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/replication_consumer.rb

Overview

Consumes normalized CDC work from an injected source.

ReplicationConsumer is intentionally upstream-agnostic. It does not know which upstream system produced the work. Its only job is to consume CDC Ecosystem work, flatten CDC transaction envelopes, and yield individual change events to the delivery pipeline.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: nil) ⇒ ReplicationConsumer

Returns a new instance of ReplicationConsumer.

Parameters:

  • source (#each, nil) (defaults to: nil)

    injectable CDC work stream



14
15
16
# File 'lib/mammoth/replication_consumer.rb', line 14

def initialize(source: nil)
  @source = source
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/mammoth/replication_consumer.rb', line 11

def source
  @source
end

Instance Method Details

#start {|event| ... } ⇒ Integer

Consume normalized CDC work from the configured source.

Yield Parameters:

  • event (Object)

    CDC::Core::ChangeEvent-compatible event

Returns:

  • (Integer)

    number of consumed events



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mammoth/replication_consumer.rb', line 22

def start
  return enum_for(:start) unless block_given?

  count = 0

  each_event do |event|
    yield event
    count += 1
  end

  count
end