Class: Deimos::ActiveRecordConsumer
- Includes:
- Deimos::ActiveRecordConsume::BatchConsumption, Deimos::ActiveRecordConsume::MessageConsumption
- Defined in:
- lib/deimos/active_record_consumer.rb
Overview
To configure batch vs. message mode, change the delivery mode of your Phobos listener. Message-by-message -> use ‘delivery: message` or `delivery: batch` Batch -> use `delivery: inline_batch`
Class Method Summary collapse
- .bulk_import_id_column ⇒ String?
- .bulk_import_id_generator ⇒ Proc
-
.compacted(val) ⇒ void
only the last message for each unique key in a batch is processed.
- .max_db_batch_size(limit) ⇒ void
-
.record_class(klass) ⇒ void
database.
- .replace_associations ⇒ Boolean
Instance Method Summary collapse
-
#initialize ⇒ ActiveRecordConsumer
constructor
Setup.
-
#process_message?(_payload) ⇒ Boolean
Override this message to conditionally save records.
-
#record_attributes(payload, _key = nil) ⇒ Hash
Override this method (with ‘super`) if you want to add/change the default attributes set to the new/existing record.
Methods included from Deimos::ActiveRecordConsume::BatchConsumption
Methods included from Deimos::ActiveRecordConsume::MessageConsumption
#assign_key, #consume, #destroy_record, #fetch_record, #save_record
Methods inherited from Consumer
#decode_key, #decode_message, decoder, key_decoder
Methods included from Consume::BatchConsumption
#around_consume_batch, #consume_batch
Methods included from Consume::MessageConsumption
Constructor Details
#initialize ⇒ ActiveRecordConsumer
Setup
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/deimos/active_record_consumer.rb', line 63 def initialize @klass = self.class.config[:record_class] @converter = ActiveRecordConsume::SchemaModelConverter.new(self.class.decoder, @klass) if self.class.config[:key_schema] @key_converter = ActiveRecordConsume::SchemaModelConverter.new(self.class.key_decoder, @klass) end @compacted = self.class.config[:compacted] != false end |
Class Method Details
.bulk_import_id_column ⇒ String?
34 35 36 |
# File 'lib/deimos/active_record_consumer.rb', line 34 def bulk_import_id_column config[:bulk_import_id_column] end |
.bulk_import_id_generator ⇒ Proc
39 40 41 |
# File 'lib/deimos/active_record_consumer.rb', line 39 def bulk_import_id_generator config[:bulk_import_id_generator] end |
.compacted(val) ⇒ void
This method returns an undefined value.
only the last message for each unique key in a batch is processed.
51 52 53 |
# File 'lib/deimos/active_record_consumer.rb', line 51 def compacted(val) config[:compacted] = val end |
.max_db_batch_size(limit) ⇒ void
This method returns an undefined value.
57 58 59 |
# File 'lib/deimos/active_record_consumer.rb', line 57 def max_db_batch_size(limit) config[:max_db_batch_size] = limit end |
.record_class(klass) ⇒ void
This method returns an undefined value.
database.
29 30 31 |
# File 'lib/deimos/active_record_consumer.rb', line 29 def record_class(klass) config[:record_class] = klass end |
.replace_associations ⇒ Boolean
44 45 46 |
# File 'lib/deimos/active_record_consumer.rb', line 44 def replace_associations config[:replace_associations] end |
Instance Method Details
#process_message?(_payload) ⇒ Boolean
Override this message to conditionally save records
87 88 89 |
# File 'lib/deimos/active_record_consumer.rb', line 87 def (_payload) true end |
#record_attributes(payload, _key = nil) ⇒ Hash
Override this method (with ‘super`) if you want to add/change the default attributes set to the new/existing record.
79 80 81 |
# File 'lib/deimos/active_record_consumer.rb', line 79 def record_attributes(payload, _key=nil) @converter.convert(payload) end |