karafka-rdkafka 0.19.0 → 0.19.2.rc1
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
- checksums.yaml.gz.sig +0 -0
- data/.github/CODEOWNERS +3 -0
- data/.github/workflows/ci.yml +26 -10
- data/.github/workflows/verify-action-pins.yml +16 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +13 -11
- data/docker-compose.yml +1 -1
- data/lib/rdkafka/bindings.rb +25 -1
- data/lib/rdkafka/config.rb +8 -4
- data/lib/rdkafka/consumer/headers.rb +14 -3
- data/lib/rdkafka/native_kafka.rb +4 -2
- data/lib/rdkafka/producer/partitions_count_cache.rb +216 -0
- data/lib/rdkafka/producer.rb +52 -35
- data/lib/rdkafka/version.rb +1 -1
- data/lib/rdkafka.rb +1 -0
- data/renovate.json +13 -1
- data/spec/rdkafka/admin_spec.rb +12 -10
- data/spec/rdkafka/bindings_spec.rb +0 -9
- data/spec/rdkafka/config_spec.rb +17 -15
- data/spec/rdkafka/consumer/headers_spec.rb +26 -10
- data/spec/rdkafka/producer/partitions_count_cache_spec.rb +359 -0
- data/spec/rdkafka/producer/partitions_count_spec.rb +359 -0
- data/spec/rdkafka/producer_spec.rb +156 -3
- data/spec/spec_helper.rb +9 -0
- data.tar.gz.sig +1 -2
- metadata +10 -3
- metadata.gz.sig +0 -0
@@ -654,12 +654,11 @@ describe Rdkafka::Producer do
|
|
654
654
|
|
655
655
|
context 'when the partition count value was cached but time expired' do
|
656
656
|
before do
|
657
|
-
|
658
|
-
producer.partition_count('example_topic')
|
657
|
+
::Rdkafka::Producer.partitions_count_cache = Rdkafka::Producer::PartitionsCountCache.new
|
659
658
|
allow(::Rdkafka::Metadata).to receive(:new).and_call_original
|
660
659
|
end
|
661
660
|
|
662
|
-
it 'expect
|
661
|
+
it 'expect to query it again' do
|
663
662
|
producer.partition_count('example_topic')
|
664
663
|
expect(::Rdkafka::Metadata).to have_received(:new)
|
665
664
|
end
|
@@ -1002,4 +1001,158 @@ describe Rdkafka::Producer do
|
|
1002
1001
|
end
|
1003
1002
|
end
|
1004
1003
|
end
|
1004
|
+
|
1005
|
+
describe "#produce with headers" do
|
1006
|
+
it "should produce a message with array headers" do
|
1007
|
+
headers = {
|
1008
|
+
"version" => ["2.1.3", "2.1.4"],
|
1009
|
+
"type" => "String"
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
report = producer.produce(
|
1013
|
+
topic: "consume_test_topic",
|
1014
|
+
key: "key headers",
|
1015
|
+
headers: headers
|
1016
|
+
).wait
|
1017
|
+
|
1018
|
+
message = wait_for_message(topic: "consume_test_topic", consumer: consumer, delivery_report: report)
|
1019
|
+
expect(message).to be
|
1020
|
+
expect(message.key).to eq('key headers')
|
1021
|
+
expect(message.headers['type']).to eq('String')
|
1022
|
+
expect(message.headers['version']).to eq(["2.1.3", "2.1.4"])
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
it "should produce a message with single value headers" do
|
1026
|
+
headers = {
|
1027
|
+
"version" => "2.1.3",
|
1028
|
+
"type" => "String"
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
report = producer.produce(
|
1032
|
+
topic: "consume_test_topic",
|
1033
|
+
key: "key headers",
|
1034
|
+
headers: headers
|
1035
|
+
).wait
|
1036
|
+
|
1037
|
+
message = wait_for_message(topic: "consume_test_topic", consumer: consumer, delivery_report: report)
|
1038
|
+
expect(message).to be
|
1039
|
+
expect(message.key).to eq('key headers')
|
1040
|
+
expect(message.headers['type']).to eq('String')
|
1041
|
+
expect(message.headers['version']).to eq('2.1.3')
|
1042
|
+
end
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
describe 'with active statistics callback' do
|
1046
|
+
let(:producer) do
|
1047
|
+
rdkafka_producer_config('statistics.interval.ms': 1_000).producer
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
let(:count_cache_hash) { described_class.partitions_count_cache.to_h }
|
1051
|
+
let(:pre_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
|
1052
|
+
let(:post_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
|
1053
|
+
|
1054
|
+
context "when using partition key" do
|
1055
|
+
before do
|
1056
|
+
Rdkafka::Config.statistics_callback = ->(*) {}
|
1057
|
+
|
1058
|
+
# This call will make a blocking request to the metadata cache
|
1059
|
+
producer.produce(
|
1060
|
+
topic: "produce_test_topic",
|
1061
|
+
payload: "payload headers",
|
1062
|
+
partition_key: "test"
|
1063
|
+
).wait
|
1064
|
+
|
1065
|
+
pre_statistics_ttl
|
1066
|
+
|
1067
|
+
# We wait to make sure that statistics are triggered and that there is a refresh
|
1068
|
+
sleep(1.5)
|
1069
|
+
|
1070
|
+
post_statistics_ttl
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
it 'expect to update ttl on the partitions count cache via statistics' do
|
1074
|
+
expect(pre_statistics_ttl).to be < post_statistics_ttl
|
1075
|
+
end
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
context "when not using partition key" do
|
1079
|
+
before do
|
1080
|
+
Rdkafka::Config.statistics_callback = ->(*) {}
|
1081
|
+
|
1082
|
+
# This call will make a blocking request to the metadata cache
|
1083
|
+
producer.produce(
|
1084
|
+
topic: "produce_test_topic",
|
1085
|
+
payload: "payload headers"
|
1086
|
+
).wait
|
1087
|
+
|
1088
|
+
pre_statistics_ttl
|
1089
|
+
|
1090
|
+
# We wait to make sure that statistics are triggered and that there is a refresh
|
1091
|
+
sleep(1.5)
|
1092
|
+
|
1093
|
+
# This will anyhow be populated from statistic
|
1094
|
+
post_statistics_ttl
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
it 'expect not to update ttl on the partitions count cache via blocking but via use stats' do
|
1098
|
+
expect(pre_statistics_ttl).to be_nil
|
1099
|
+
expect(post_statistics_ttl).not_to be_nil
|
1100
|
+
end
|
1101
|
+
end
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
describe 'without active statistics callback' do
|
1105
|
+
let(:producer) do
|
1106
|
+
rdkafka_producer_config('statistics.interval.ms': 1_000).producer
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
let(:count_cache_hash) { described_class.partitions_count_cache.to_h }
|
1110
|
+
let(:pre_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
|
1111
|
+
let(:post_statistics_ttl) { count_cache_hash.fetch('produce_test_topic', [])[0] }
|
1112
|
+
|
1113
|
+
context "when using partition key" do
|
1114
|
+
before do
|
1115
|
+
# This call will make a blocking request to the metadata cache
|
1116
|
+
producer.produce(
|
1117
|
+
topic: "produce_test_topic",
|
1118
|
+
payload: "payload headers",
|
1119
|
+
partition_key: "test"
|
1120
|
+
).wait
|
1121
|
+
|
1122
|
+
pre_statistics_ttl
|
1123
|
+
|
1124
|
+
# We wait to make sure that statistics are triggered and that there is a refresh
|
1125
|
+
sleep(1.5)
|
1126
|
+
|
1127
|
+
post_statistics_ttl
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
it 'expect not to update ttl on the partitions count cache via statistics' do
|
1131
|
+
expect(pre_statistics_ttl).to eq post_statistics_ttl
|
1132
|
+
end
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
context "when not using partition key" do
|
1136
|
+
before do
|
1137
|
+
# This call will make a blocking request to the metadata cache
|
1138
|
+
producer.produce(
|
1139
|
+
topic: "produce_test_topic",
|
1140
|
+
payload: "payload headers"
|
1141
|
+
).wait
|
1142
|
+
|
1143
|
+
pre_statistics_ttl
|
1144
|
+
|
1145
|
+
# We wait to make sure that statistics are triggered and that there is a refresh
|
1146
|
+
sleep(1.5)
|
1147
|
+
|
1148
|
+
# This should not be populated because stats are not in use
|
1149
|
+
post_statistics_ttl
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
it 'expect not to update ttl on the partitions count cache via anything' do
|
1153
|
+
expect(pre_statistics_ttl).to be_nil
|
1154
|
+
expect(post_statistics_ttl).to be_nil
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
end
|
1005
1158
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,9 @@ def rdkafka_base_config
|
|
18
18
|
:"api.version.request" => false,
|
19
19
|
:"broker.version.fallback" => "1.0",
|
20
20
|
:"bootstrap.servers" => "localhost:9092",
|
21
|
+
# Display statistics and refresh often just to cover those in specs
|
22
|
+
:'statistics.interval.ms' => 1_000,
|
23
|
+
:'topic.metadata.refresh.interval.ms' => 1_000
|
21
24
|
}
|
22
25
|
end
|
23
26
|
|
@@ -125,6 +128,12 @@ RSpec.configure do |config|
|
|
125
128
|
config.filter_run focus: true
|
126
129
|
config.run_all_when_everything_filtered = true
|
127
130
|
|
131
|
+
config.before(:each) do
|
132
|
+
Rdkafka::Config.statistics_callback = nil
|
133
|
+
# We need to clear it so state does not leak between specs
|
134
|
+
Rdkafka::Producer.partitions_count_cache.to_h.clear
|
135
|
+
end
|
136
|
+
|
128
137
|
config.before(:suite) do
|
129
138
|
admin = rdkafka_config.admin
|
130
139
|
{
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
��Y@�J�w�vr���|���%W��6^[�G����q�3�D���ڟ0�:d6����#�ă�C*�Ƌ{����Lw�~��A�m�;6Ey��$0�D��@����`�-5@� �V�%'��L��'$��s����X|�!b*�[�,�����6�$Zli�Ek��¹g�}M��fi�0:���?����UЖJ��ki>i�$u*�����R&��Q�P"š՚|$�cyJ��U"Ф�]QB�L4��|�������R�vq�ۃW'F�17(��ǻX���@]J�~�F�"��q�Ŝ���OJ�09�D�1Pq��>Q�/��4�d��O��oa/$/C��'h��Lr�(��\
|
1
|
+
%��;��l�x�_9|�e�5�Bv77)��N^lӷ�o<`x���5��jYKFdJ��"/V5��p�\
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karafka-rdkafka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.19.
|
4
|
+
version: 0.19.2.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thijs Cadier
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
i9zWxov0mr44TWegTVeypcWGd/0nxu1+QHVNHJrpqlPBRvwQsUm7fwmRInGpcaB8
|
36
36
|
ap8wNYvryYzrzvzUxIVFBVM5PacgkFqRmolCa8I7tdKQN+R1
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: ffi
|
@@ -171,8 +171,10 @@ extensions:
|
|
171
171
|
- ext/Rakefile
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".github/CODEOWNERS"
|
174
175
|
- ".github/FUNDING.yml"
|
175
176
|
- ".github/workflows/ci.yml"
|
177
|
+
- ".github/workflows/verify-action-pins.yml"
|
176
178
|
- ".gitignore"
|
177
179
|
- ".rspec"
|
178
180
|
- ".ruby-gemset"
|
@@ -231,6 +233,7 @@ files:
|
|
231
233
|
- lib/rdkafka/producer.rb
|
232
234
|
- lib/rdkafka/producer/delivery_handle.rb
|
233
235
|
- lib/rdkafka/producer/delivery_report.rb
|
236
|
+
- lib/rdkafka/producer/partitions_count_cache.rb
|
234
237
|
- lib/rdkafka/version.rb
|
235
238
|
- renovate.json
|
236
239
|
- spec/rdkafka/abstract_handle_spec.rb
|
@@ -258,6 +261,8 @@ files:
|
|
258
261
|
- spec/rdkafka/native_kafka_spec.rb
|
259
262
|
- spec/rdkafka/producer/delivery_handle_spec.rb
|
260
263
|
- spec/rdkafka/producer/delivery_report_spec.rb
|
264
|
+
- spec/rdkafka/producer/partitions_count_cache_spec.rb
|
265
|
+
- spec/rdkafka/producer/partitions_count_spec.rb
|
261
266
|
- spec/rdkafka/producer_spec.rb
|
262
267
|
- spec/spec_helper.rb
|
263
268
|
licenses:
|
@@ -284,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
289
|
- !ruby/object:Gem::Version
|
285
290
|
version: '0'
|
286
291
|
requirements: []
|
287
|
-
rubygems_version: 3.6.
|
292
|
+
rubygems_version: 3.6.7
|
288
293
|
specification_version: 4
|
289
294
|
summary: The rdkafka gem is a modern Kafka client library for Ruby based on librdkafka.
|
290
295
|
It wraps the production-ready C client using the ffi gem and targets Kafka 1.0+
|
@@ -315,5 +320,7 @@ test_files:
|
|
315
320
|
- spec/rdkafka/native_kafka_spec.rb
|
316
321
|
- spec/rdkafka/producer/delivery_handle_spec.rb
|
317
322
|
- spec/rdkafka/producer/delivery_report_spec.rb
|
323
|
+
- spec/rdkafka/producer/partitions_count_cache_spec.rb
|
324
|
+
- spec/rdkafka/producer/partitions_count_spec.rb
|
318
325
|
- spec/rdkafka/producer_spec.rb
|
319
326
|
- spec/spec_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|