Open
Description
We have something like
class ApplicationConsumer < Karafka::BaseConsumer
def self.on_unknown(message)
…
end
def consume
messages.each { |message| consume_single(message) }
end
def consume_single(message)
return self.class.on_unknown(message) unless validate(message)
MyApp::Metrics.with_context(**metrics_context(message)) do
process(message)
end
end
with a bunch of code handling unknown messages, errors and adding some context for metrics and error reporting in AppicationConsumer
and all other consumers inherited from this one.
In specs it's tested (or was tested in karafka-1) like
RSpec.describe ApplicationConsumer do
let(:consumer) do
Class.new(described_class) do
def initialize; end # rubocop:disable Style/RedundantInitialize required to avoid exception with different arity
end.new
end
end
and with karafka-2 it fails because karafka-testing implies that consumer has topic set, for example here and here.
It could be workarounded by
before
consumer_group = Karafka::Routing::ConsumerGroup.new('foo')
consumer.topic = Karafka::Routing::Topic.new('foo', consumer_group)
end
but would be good to retain the ability to test topic-less consumers or at least simplify/document how consumer group should be created.