Class: Karafka::Testing::SpecProducerClient

Inherits:
WaterDrop::Clients::Buffered
  • Object
show all
Defined in:
lib/karafka/testing/spec_producer_client.rb

Overview

Spec producer client used to buffer messages that we send out in specs

Instance Method Summary collapse

Constructor Details

#initialize(rspec) ⇒ SpecProducerClient

Returns a new instance of SpecProducerClient.

Parameters:

  • rspec (RSpec::Core::ExampleGroup)

    rspec example we need to hold to trigger actions on it that are rspec context aware



9
10
11
12
# File 'lib/karafka/testing/spec_producer_client.rb', line 9

def initialize(rspec)
  super(nil)
  @rspec = rspec
end

Instance Method Details

#produce(message) ⇒ Object

“Produces” message to Kafka. That is, it acknowledges it locally, adds it to the internal buffer and adds it (if needed) into the current consumer messages buffer

Parameters:

  • message (Hash)

    Karafka.producer.produce_sync message hash



17
18
19
20
21
# File 'lib/karafka/testing/spec_producer_client.rb', line 17

def produce(message)
  @rspec._karafka_add_message_to_consumer_if_needed(message)

  super
end