-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update Consumer#poll raise an exception when the message is an …
…error The message object returned by `LibRdKafka.consumer_poll` can be a proper message or an event or error. In the case of an error we will now raise a ConsumerException by default. The previous behaviour can be maintained by passing `raise_on_error: false`.
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "../spec_helper" | ||
|
||
describe "Consumer error handling" do | ||
describe "#poll" do | ||
it "raises errors by default" do | ||
consumer = Kafka::Consumer.new({"bootstrap.servers" => "127.0.0.1:9094", "group.id" => "foo_group", "broker.address.family" => "v4"}) | ||
consumer.subscribe("non-existent-topic") | ||
|
||
expect_raises(Kafka::ConsumerException, "librdkafka error - Broker: Unknown topic or partition") do | ||
consumer.poll(1000) | ||
end | ||
ensure | ||
consumer.try(&.close) | ||
end | ||
|
||
it "doesn't raise errors when raise_on_error is false" do | ||
consumer = Kafka::Consumer.new({"bootstrap.servers" => "127.0.0.1:9094", "group.id" => "foo_group", "broker.address.family" => "v4"}) | ||
consumer.subscribe("non-existent-topic") | ||
|
||
message = consumer.poll(1000, raise_on_error: false) | ||
message.not_nil!.err.not_nil!.message.should eq "Broker: Unknown topic or partition" | ||
ensure | ||
consumer.try(&.close) | ||
end | ||
end | ||
|
||
describe "#each" do | ||
it "raises errors by default" do | ||
consumer = Kafka::Consumer.new({"bootstrap.servers" => "127.0.0.1:9094", "group.id" => "foo_group", "broker.address.family" => "v4"}) | ||
consumer.subscribe("non-existent-topic") | ||
|
||
expect_raises(Kafka::ConsumerException, "librdkafka error - Broker: Unknown topic or partition") do | ||
consumer.each(1000) do |_message| | ||
break | ||
end | ||
end | ||
ensure | ||
consumer.try(&.close) | ||
end | ||
|
||
it "doesn't raise errors when raise_on_error is false" do | ||
consumer = Kafka::Consumer.new({"bootstrap.servers" => "127.0.0.1:9094", "group.id" => "foo_group", "broker.address.family" => "v4"}) | ||
consumer.subscribe("non-existent-topic") | ||
|
||
consumer.each(1000, raise_on_error: false) do |message| | ||
message.err.not_nil!.message.should eq "Broker: Unknown topic or partition" | ||
break | ||
end | ||
ensure | ||
consumer.try(&.close) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters