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 job is to consume CDC Ecosystem work and yield either individual change events or transaction envelopes depending on Mammoth's configured delivery unit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: nil, delivery_unit: :event) ⇒ ReplicationConsumer

Returns a new instance of ReplicationConsumer.

Parameters:

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

    injectable CDC work stream

  • delivery_unit (String, Symbol) (defaults to: :event)

    :event or :transaction



16
17
18
19
# File 'lib/mammoth/replication_consumer.rb', line 16

def initialize(source: nil, delivery_unit: :event)
  @source = source
  @delivery_unit = delivery_unit.to_sym
end

Instance Attribute Details

#delivery_unitObject (readonly)

Returns the value of attribute delivery_unit.



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

def delivery_unit
  @delivery_unit
end

#sourceObject (readonly)

Returns the value of attribute source.



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

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



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mammoth/replication_consumer.rb', line 25

def start
  return enum_for(:start) unless block_given?

  count = 0

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

  count
end