karafka-rdkafka 0.19.4 → 0.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/push.yml +2 -3
- data/CHANGELOG.md +3 -0
- data/Rakefile +0 -2
- data/lib/rdkafka/producer.rb +7 -0
- data/lib/rdkafka/version.rb +1 -1
- data/spec/rdkafka/producer_spec.rb +61 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84a931a800cf4fb0e62f0d15de7f53e5c5845e8edfcd240f1939ec445050bdb
|
4
|
+
data.tar.gz: f12b221a26faa281f4c9c90b2a55ac8ebc623cf1aa882b0ce8e7ae274aa6a122
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225e690444b46ea2469f0a92beb7e27cd105c49b1649c022163996fb994ed67c9adac95573bfa96f23134732a3e4d41f5dbffc970bdffd699de664b4b1b89e73
|
7
|
+
data.tar.gz: 1fcb61fd0d7ca98537b59d15235fd84ab202e020828d36cab07b9ecf837eb845fafa7a6624eb760902c5b50050134a30361f16429f2442f43491f76c57bb4340
|
data/.github/workflows/ci.yml
CHANGED
@@ -51,7 +51,7 @@ jobs:
|
|
51
51
|
docker compose up -d || (sleep 5 && docker compose up -d)
|
52
52
|
|
53
53
|
- name: Set up Ruby
|
54
|
-
uses: ruby/setup-ruby@
|
54
|
+
uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
|
55
55
|
with:
|
56
56
|
ruby-version: ${{matrix.ruby}}
|
57
57
|
bundler-cache: true
|
@@ -86,7 +86,7 @@ jobs:
|
|
86
86
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
87
87
|
|
88
88
|
- name: Set up Ruby
|
89
|
-
uses: ruby/setup-ruby@
|
89
|
+
uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
|
90
90
|
with:
|
91
91
|
ruby-version: ${{matrix.ruby}}
|
92
92
|
bundler-cache: false
|
data/.github/workflows/push.yml
CHANGED
@@ -24,7 +24,7 @@ jobs:
|
|
24
24
|
fetch-depth: 0
|
25
25
|
|
26
26
|
- name: Set up Ruby
|
27
|
-
uses: ruby/setup-ruby@
|
27
|
+
uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
|
28
28
|
with:
|
29
29
|
bundler-cache: false
|
30
30
|
|
@@ -34,5 +34,4 @@ jobs:
|
|
34
34
|
bundle install --jobs 4 --retry 3
|
35
35
|
cd ext && bundle exec rake
|
36
36
|
|
37
|
-
#
|
38
|
-
- uses: rubygems/release-gem@9e85cb11501bebc2ae661c1500176316d3987059 # v1
|
37
|
+
- uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
data/lib/rdkafka/producer.rb
CHANGED
@@ -301,6 +301,13 @@ module Rdkafka
|
|
301
301
|
|
302
302
|
topic_metadata ? topic_metadata[:partition_count] : -1
|
303
303
|
end
|
304
|
+
rescue Rdkafka::RdkafkaError => e
|
305
|
+
# If the topic does not exist, it will be created or if not allowed another error will be
|
306
|
+
# raised. We here return -1 so this can happen without early error happening on metadata
|
307
|
+
# discovery.
|
308
|
+
return -1 if e.code == :unknown_topic_or_part
|
309
|
+
|
310
|
+
raise(e)
|
304
311
|
end
|
305
312
|
|
306
313
|
# Produces a message to a Kafka topic. The message is added to rdkafka's queue, call {DeliveryHandle#wait wait} on the returned delivery handle to make sure it is delivered.
|
data/lib/rdkafka/version.rb
CHANGED
@@ -364,6 +364,48 @@ describe Rdkafka::Producer do
|
|
364
364
|
expect(message.key).to eq "key utf8"
|
365
365
|
end
|
366
366
|
|
367
|
+
it "should produce a message to a non-existing topic with key and partition key" do
|
368
|
+
new_topic = "it-#{SecureRandom.uuid}"
|
369
|
+
|
370
|
+
handle = producer.produce(
|
371
|
+
# Needs to be a new topic each time
|
372
|
+
topic: new_topic,
|
373
|
+
payload: "payload",
|
374
|
+
key: "key",
|
375
|
+
partition_key: "partition_key",
|
376
|
+
label: "label"
|
377
|
+
)
|
378
|
+
|
379
|
+
# Should be pending at first
|
380
|
+
expect(handle.pending?).to be true
|
381
|
+
expect(handle.label).to eq "label"
|
382
|
+
|
383
|
+
# Check delivery handle and report
|
384
|
+
report = handle.wait(max_wait_timeout: 5)
|
385
|
+
expect(handle.pending?).to be false
|
386
|
+
expect(report).not_to be_nil
|
387
|
+
expect(report.partition).to eq 0
|
388
|
+
expect(report.offset).to be >= 0
|
389
|
+
expect(report.label).to eq "label"
|
390
|
+
|
391
|
+
# Flush and close producer
|
392
|
+
producer.flush
|
393
|
+
producer.close
|
394
|
+
|
395
|
+
# Consume message and verify its content
|
396
|
+
message = wait_for_message(
|
397
|
+
topic: new_topic,
|
398
|
+
delivery_report: report,
|
399
|
+
consumer: consumer
|
400
|
+
)
|
401
|
+
expect(message.partition).to eq 0
|
402
|
+
expect(message.payload).to eq "payload"
|
403
|
+
expect(message.key).to eq "key"
|
404
|
+
# Since api.version.request is on by default we will get
|
405
|
+
# the message creation timestamp if it's not set.
|
406
|
+
expect(message.timestamp).to be_within(10).of(Time.now)
|
407
|
+
end
|
408
|
+
|
367
409
|
context "timestamp" do
|
368
410
|
it "should raise a type error if not nil, integer or time" do
|
369
411
|
expect {
|
@@ -637,6 +679,25 @@ describe Rdkafka::Producer do
|
|
637
679
|
end
|
638
680
|
end
|
639
681
|
|
682
|
+
context "when topic does not exist and allow.auto.create.topics is false" do
|
683
|
+
let(:producer) do
|
684
|
+
rdkafka_producer_config(
|
685
|
+
"bootstrap.servers": "localhost:9092",
|
686
|
+
"message.timeout.ms": 100,
|
687
|
+
"allow.auto.create.topics": false
|
688
|
+
).producer
|
689
|
+
end
|
690
|
+
|
691
|
+
it "should contain the error in the response when not deliverable" do
|
692
|
+
handler = producer.produce(topic: "it-#{SecureRandom.uuid}", payload: nil, label: 'na')
|
693
|
+
# Wait for the async callbacks and delivery registry to update
|
694
|
+
sleep(2)
|
695
|
+
expect(handler.create_result.error).to be_a(Rdkafka::RdkafkaError)
|
696
|
+
expect(handler.create_result.error.code).to eq(:msg_timed_out)
|
697
|
+
expect(handler.create_result.label).to eq('na')
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
640
701
|
describe '#partition_count' do
|
641
702
|
it { expect(producer.partition_count('example_topic')).to eq(1) }
|
642
703
|
|