Module: K8::Lib

Defined in:
lib/k8/lib.rb,
lib/k8/lib/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"1.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.buffer_sizeObject

Returns the value of attribute buffer_size.



19
20
21
# File 'lib/k8/lib.rb', line 19

def buffer_size
  @buffer_size
end

.partition_keyObject

Returns the value of attribute partition_key.



19
20
21
# File 'lib/k8/lib.rb', line 19

def partition_key
  @partition_key
end

.topic_nameObject

Returns the value of attribute topic_name.



19
20
21
# File 'lib/k8/lib.rb', line 19

def topic_name
  @topic_name
end

Class Method Details

.config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (K8::Lib)

    the object that the method was called on



20
21
22
# File 'lib/k8/lib.rb', line 20

def config
  yield self
end

.produce(message, t, partition_key = '') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/k8/lib.rb', line 25

def produce(message, t, partition_key = '')
  # This will queue the two messages in the internal buffer.
  # DeliveryBoy.produce(comment.to_json, topic: "comments")

  if partition_key.nil? || partition_key.empty?
    DeliveryBoy.produce(message.to_json, topic: (t || topic_name))
  else 
    DeliveryBoy.produce(message.to_json, topic: (t || topic_name), partition_key: partition_key)
  end

  # This will deliver all messages in the buffer to Kafka.
  # This call is blocking.
  if DeliveryBoy.buffer_size >= buffer_size
    DeliveryBoy.deliver_messages
  end
  return 'done'
end