Class: Deimos::Consumer
- Inherits:
-
Object
- Object
- Deimos::Consumer
- Defined in:
- lib/deimos/consumer.rb
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`
Direct Known Subclasses
ActiveRecordConsumer, BatchConsumer, Utils::MessageBankHandler
Class Method Summary collapse
Instance Method Summary collapse
-
#decode_key(key) ⇒ Object
Helper method to decode an encoded key.
-
#decode_message(payload) ⇒ Object
Helper method to decode an encoded message.
Methods included from Deimos::Consume::BatchConsumption
#around_consume_batch, #consume_batch
Methods included from Deimos::Consume::MessageConsumption
Class Method Details
.decoder ⇒ Deimos::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_decoder ⇒ Deimos::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
#decode_key(key) ⇒ Object
Helper method to decode an encoded 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.
57 58 59 60 61 62 63 64 |
# File 'lib/deimos/consumer.rb', line 57 def (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 |