Class: GovukMessageQueueConsumer::BatchConsumer
- Defined in:
- lib/govuk_message_queue_consumer/batch_consumer.rb
Constant Summary collapse
- HANDLE_BATCHES =
true- DEFAULT_BATCH_SIZE =
100- DEFAULT_BATCH_TIMEOUT =
5- NUMBER_OF_MESSAGES_TO_PREFETCH =
we want to increase the prefetch size here to the batch size so that we don’t need to do multiple fetches for a batch.
DEFAULT_BATCH_SIZE
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BatchConsumer
constructor
A new instance of BatchConsumer.
- #run ⇒ Object
-
#stop ⇒ Object
used for testing to stop processing in a different thread.
Constructor Details
#initialize(options = {}) ⇒ BatchConsumer
Returns a new instance of BatchConsumer.
10 11 12 13 14 15 |
# File 'lib/govuk_message_queue_consumer/batch_consumer.rb', line 10 def initialize(={}) opts = .dup @batch_size = opts.delete(:batch_size) || DEFAULT_BATCH_SIZE @batch_timeout = opts.delete(:batch_timeout) || DEFAULT_BATCH_TIMEOUT super(opts) end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/govuk_message_queue_consumer/batch_consumer.rb', line 17 def run @rabbitmq_connection.start @running = true while @running do process_batch end end |
#stop ⇒ Object
used for testing to stop processing in a different thread
26 27 28 |
# File 'lib/govuk_message_queue_consumer/batch_consumer.rb', line 26 def stop @running = false end |