Class: Deimos::Consumer

Inherits:
Object
  • Object
show all
Includes:
Deimos::Consume::BatchConsumption, Deimos::Consume::MessageConsumption, SharedConfig
Defined in:
lib/deimos/consumer.rb,
sig/defs.rbs

Overview

Basic consumer class. Inherit from this class and override either consume or consume_batch, depending on the delivery mode of your listener. consume -> use delivery :message or delivery :batch consume_batch -> use delivery :inline_batch

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decoderDeimos::SchemaBackends::Base



21
22
23
24
# File 'lib/deimos/consumer.rb', line 21

def decoder
  @decoder ||= Deimos.schema_backend(schema: config[:schema],
                                     namespace: config[:namespace])
end

.key_decoderDeimos::SchemaBackends::Base



27
28
29
30
# File 'lib/deimos/consumer.rb', line 27

def key_decoder
  @key_decoder ||= Deimos.schema_backend(schema: config[:key_schema],
                                         namespace: config[:namespace])
end

Instance Method Details

#around_consumevoid

This method returns an undefined value.

@param payload

@param metadata



155
# File 'sig/defs.rbs', line 155

def around_consume: (String payload, ::Hash[untyped, untyped] ) -> void

#around_consume_batchvoid

This method returns an undefined value.

@param batch

@param metadata



143
# File 'sig/defs.rbs', line 143

def around_consume_batch: (::Array[String] batch, ::Hash[untyped, untyped] ) -> void

#consumevoid

This method returns an undefined value.

Consume incoming messages.

@param _payload

@param _metadata



162
# File 'sig/defs.rbs', line 162

def consume: (String _payload, ::Hash[untyped, untyped] ) -> void

#consume_batchvoid

This method returns an undefined value.

Consume a batch of incoming messages.

@param _payloads

@param _metadata



150
# File 'sig/defs.rbs', line 150

def consume_batch: (::Array[Phobos::BatchMessage] _payloads, ::Hash[untyped, untyped] ) -> void

#decode_key(key) ⇒ Object

Helper method to decode an encoded key.

@param key

@return — the decoded key.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/deimos/consumer.rb', line 36

def decode_key(key)
  return nil if key.nil?

  config = self.class.config
  unless config[:key_configured]
    raise 'No key config given - if you are not decoding keys, please use '\
      '`key_config plain: true`'
  end

  if config[:key_field]
    self.class.decoder.decode_key(key, config[:key_field])
  elsif config[:key_schema]
    self.class.key_decoder.decode(key, schema: config[:key_schema])
  else # no encoding
    key
  end
end

#decode_message(payload) ⇒ Object

Helper method to decode an encoded message.

@param payload

@return — the decoded message.



57
58
59
60
61
62
63
64
# File 'lib/deimos/consumer.rb', line 57

def decode_message(payload)
  decoded_payload = payload.nil? ? nil : self.class.decoder.decode(payload)
  return decoded_payload unless Utils::SchemaClass.use?(self.class.config.to_h)

  Utils::SchemaClass.instance(decoded_payload,
                              self.class.config[:schema],
                              self.class.config[:namespace])
end