v1.4-non-rails/app/consumers/inline_batch_consumer.rb
def consume
    # You can access the params_batch as an array and just work with it
    sum = params_batch
          .map { |param| param.payload['number'] }
          .inject(0) { |accu, val| accu + val }

    Karafka.logger.info "Sum of #{params_batch.count} elements equals to: #{sum}"

    # This is not needed as automatic offset management is on, but we add it just to illustrate
    # that the karafka-testing works with this case as well
    mark_as_consumed!(params_batch.last)
  end
# Performs business logic with messages batch
Performs business logic with messages batch
Performs business logic with messages batch
def consume
    sum = params_batch
          .map { |param| param.payload['number'] }
          .inject(0) { |accu, val| accu + val }
    Karafka.logger.info "Sum of #{params_batch.count} elements equals to: #{sum}"
    mark_as_consumed!(params_batch.last)
  end
def consume sum = params_batch . map { | param | param . payload [ 'number' ] } . inject ( 0 ) { | accu , val | accu + val } Karafka . logger . info "Sum of #{params_batch.count} elements equals to: #{sum}" mark_as_consumed! ( params_batch . last ) end
Performs business logic with messages batch
Performs business logic with messages batch
# You can access the params_batch as an array and just work with it # This is not needed as automatic offset management is on, but we add it just to illustrate # that the karafka-testing works with this case as well