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



76
77
78
# File 'lib/waterdrop/clients/dummy.rb', line 76

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

Options Hash (**_args):

  • :payload (String)

    message payload

  • :key (String, nil)

    message key

  • :headers (Hash, nil)

    message headers

Returns:

  • (Handle)

    delivery handle



56
57
58
# File 'lib/waterdrop/clients/dummy.rb', line 56

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

#queue_sizeInteger Also known as: queue_length

Returns 0 as dummy client doesn’t queue any real messages

Returns:

  • (Integer)

    always 0



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

def queue_size
  0
end

#respond_to_missing?(*_args) ⇒ Boolean

Parameters:

  • _args (Object)

    anything really, this dummy is suppose to support anything

Returns:

  • (Boolean)


70
71
72
# File 'lib/waterdrop/clients/dummy.rb', line 70

def respond_to_missing?(*_args)
  true
end