Class: WaterDrop::Clients::Dummy

Inherits:
Object
  • Object
show all
Defined in:
lib/waterdrop/clients/dummy.rb

Overview

A dummy client that is supposed to be used instead of Rdkafka::Producer in case we don’t want to dispatch anything to Kafka.

It does not store anything and just ignores messages. It does however return proper delivery handle that can be materialized into a report.

Direct Known Subclasses

Buffered

Defined Under Namespace

Classes: Handle

Instance Method Summary collapse

Constructor Details

#initialize(_producer) ⇒ Dummy

Returns dummy instance.

Parameters:



44
45
46
# File 'lib/waterdrop/clients/dummy.rb', line 44

def initialize(_producer)
  @counters = Hash.new { |h, k| h[k] = -1 }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*_args) ⇒ self

Returns self for chaining cases

Parameters:

  • _args (Object)

    anything really, this dummy is suppose to support anything

Returns:

  • (self)

    returns self for chaining cases



64
65
66
# File 'lib/waterdrop/clients/dummy.rb', line 64

def method_missing(*_args)
  self || super
end

Instance Method Details

#produce(topic:, partition: 0, **_args) ⇒ Handle

“Produces” the message

Parameters:

  • topic (String, Symbol)

    topic where we want to dispatch message

  • partition (Integer) (defaults to: 0)

    target partition

  • _args (Hash)

    remaining details that are ignored in the dummy mode

Returns:

  • (Handle)

    delivery handle



53
54
55
# File 'lib/waterdrop/clients/dummy.rb', line 53

def produce(topic:, partition: 0, **_args)
  Handle.new(topic.to_s, partition, @counters["#{topic}#{partition}"] += 1)
end

#respond_to_missing?(*_args) ⇒ Boolean

Parameters:

  • _args (Object)

    anything really, this dummy is suppose to support anything

Returns:

  • (Boolean)


58
59
60
# File 'lib/waterdrop/clients/dummy.rb', line 58

def respond_to_missing?(*_args)
  true
end