Module: Karafka::Pro::Cleaner::Messages::Messages
- Defined in:
- lib/karafka/pro/cleaner/messages/messages.rb
Overview
Extensions to the messages batch allowing for automatic cleaning of each message after message is processed.
This module is prepended to Karafka::Messages::Messages to add cleaning functionality. The implementation calls super() to maintain compatibility with other libraries that also prepend modules to modify the #each method (e.g., DataDog tracing).
Instance Method Summary collapse
-
#clean!(metadata: true) ⇒ Object
Cleans all messages in the batch.
- #each(clean: false) ⇒ Object
Instance Method Details
#clean!(metadata: true) ⇒ Object
This is a convenience method that calls ‘clean!` on each message in the batch.
Cleans all messages in the batch
71 72 73 |
# File 'lib/karafka/pro/cleaner/messages/messages.rb', line 71 def clean!(metadata: true) each { || .clean!(metadata: ) } end |
#each(clean: false) ⇒ Object
Cleaning messages after we’re done with each of them and did not fail does not affect any other functionalities. The only thing that is crucial is to make sure, that if DLQ is used, that we mark each message as consumed when using this API as otherwise a cleaned message may be dispatched and that should never happen
This method calls super() to ensure compatibility with other libraries that may have prepended modules to modify #each behavior. This preserves the method chain and allows instrumentation libraries to function correctly.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/karafka/pro/cleaner/messages/messages.rb', line 54 def each(clean: false, &) if clean super() do || yield() .clean! end else super(&) end end |