rdkafka 0.13.0 → 0.31.0

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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +388 -111
  3. data/{LICENSE → MIT-LICENSE} +2 -1
  4. data/README.md +90 -43
  5. data/Rakefile +21 -23
  6. data/bin/verify_kafka_warnings +44 -0
  7. data/dist/librdkafka-2.15.1.tar.gz +0 -0
  8. data/dist/patches/rdkafka_global_init.patch +15 -0
  9. data/docker-compose-ssl.yml +39 -0
  10. data/docker-compose.yml +22 -17
  11. data/ext/Rakefile +97 -30
  12. data/lib/rdkafka/abstract_handle.rb +113 -34
  13. data/lib/rdkafka/admin/acl_binding_result.rb +51 -0
  14. data/lib/rdkafka/admin/alter_consumer_group_offsets_handle.rb +31 -0
  15. data/lib/rdkafka/admin/alter_consumer_group_offsets_report.rb +50 -0
  16. data/lib/rdkafka/admin/config_binding_result.rb +30 -0
  17. data/lib/rdkafka/admin/config_resource_binding_result.rb +19 -0
  18. data/lib/rdkafka/admin/create_acl_handle.rb +32 -0
  19. data/lib/rdkafka/admin/create_acl_report.rb +26 -0
  20. data/lib/rdkafka/admin/create_partitions_handle.rb +28 -0
  21. data/lib/rdkafka/admin/create_partitions_report.rb +7 -0
  22. data/lib/rdkafka/admin/create_topic_handle.rb +8 -7
  23. data/lib/rdkafka/admin/create_topic_report.rb +4 -1
  24. data/lib/rdkafka/admin/delete_acl_handle.rb +31 -0
  25. data/lib/rdkafka/admin/delete_acl_report.rb +25 -0
  26. data/lib/rdkafka/admin/delete_consumer_group_offsets_handle.rb +31 -0
  27. data/lib/rdkafka/admin/delete_consumer_group_offsets_report.rb +50 -0
  28. data/lib/rdkafka/admin/delete_groups_handle.rb +31 -0
  29. data/lib/rdkafka/admin/delete_groups_report.rb +27 -0
  30. data/lib/rdkafka/admin/delete_records_handle.rb +31 -0
  31. data/lib/rdkafka/admin/delete_records_report.rb +25 -0
  32. data/lib/rdkafka/admin/delete_topic_handle.rb +8 -7
  33. data/lib/rdkafka/admin/delete_topic_report.rb +4 -1
  34. data/lib/rdkafka/admin/describe_acl_handle.rb +31 -0
  35. data/lib/rdkafka/admin/describe_acl_report.rb +27 -0
  36. data/lib/rdkafka/admin/describe_cluster_handle.rb +31 -0
  37. data/lib/rdkafka/admin/describe_cluster_report.rb +48 -0
  38. data/lib/rdkafka/admin/describe_configs_handle.rb +30 -0
  39. data/lib/rdkafka/admin/describe_configs_report.rb +56 -0
  40. data/lib/rdkafka/admin/describe_consumer_groups_handle.rb +31 -0
  41. data/lib/rdkafka/admin/describe_consumer_groups_report.rb +151 -0
  42. data/lib/rdkafka/admin/describe_result_parsing.rb +47 -0
  43. data/lib/rdkafka/admin/describe_topics_handle.rb +31 -0
  44. data/lib/rdkafka/admin/describe_topics_report.rb +118 -0
  45. data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +30 -0
  46. data/lib/rdkafka/admin/incremental_alter_configs_report.rb +56 -0
  47. data/lib/rdkafka/admin/list_consumer_groups_handle.rb +31 -0
  48. data/lib/rdkafka/admin/list_consumer_groups_report.rb +83 -0
  49. data/lib/rdkafka/admin/list_offsets_handle.rb +31 -0
  50. data/lib/rdkafka/admin/list_offsets_report.rb +54 -0
  51. data/lib/rdkafka/admin.rb +1381 -38
  52. data/lib/rdkafka/bindings/admin/acls.rb +85 -0
  53. data/lib/rdkafka/bindings/admin/configs.rb +37 -0
  54. data/lib/rdkafka/bindings/admin/list_offsets.rb +26 -0
  55. data/lib/rdkafka/bindings/admin.rb +197 -0
  56. data/lib/rdkafka/bindings/callbacks.rb +100 -0
  57. data/lib/rdkafka/bindings/configuration.rb +50 -0
  58. data/lib/rdkafka/bindings/consumer.rb +83 -0
  59. data/lib/rdkafka/bindings/errors.rb +15 -0
  60. data/lib/rdkafka/bindings/handle.rb +16 -0
  61. data/lib/rdkafka/bindings/messages.rb +28 -0
  62. data/lib/rdkafka/bindings/metadata.rb +14 -0
  63. data/lib/rdkafka/bindings/polling.rb +17 -0
  64. data/lib/rdkafka/bindings/producer.rb +77 -0
  65. data/lib/rdkafka/bindings/structs.rb +62 -0
  66. data/lib/rdkafka/bindings.rb +69 -294
  67. data/lib/rdkafka/callbacks/alter_consumer_group_offsets_handler.rb +65 -0
  68. data/lib/rdkafka/callbacks/base_handler.rb +62 -0
  69. data/lib/rdkafka/callbacks/create_acl_handler.rb +37 -0
  70. data/lib/rdkafka/callbacks/create_partitions_handler.rb +37 -0
  71. data/lib/rdkafka/callbacks/create_topic_handler.rb +37 -0
  72. data/lib/rdkafka/callbacks/delete_acl_handler.rb +42 -0
  73. data/lib/rdkafka/callbacks/delete_consumer_group_offsets_handler.rb +65 -0
  74. data/lib/rdkafka/callbacks/delete_groups_handler.rb +37 -0
  75. data/lib/rdkafka/callbacks/delete_records_handler.rb +38 -0
  76. data/lib/rdkafka/callbacks/delete_topic_handler.rb +37 -0
  77. data/lib/rdkafka/callbacks/describe_acl_handler.rb +35 -0
  78. data/lib/rdkafka/callbacks/describe_cluster_handler.rb +36 -0
  79. data/lib/rdkafka/callbacks/describe_configs_handler.rb +42 -0
  80. data/lib/rdkafka/callbacks/describe_consumer_groups_handler.rb +36 -0
  81. data/lib/rdkafka/callbacks/describe_topics_handler.rb +36 -0
  82. data/lib/rdkafka/callbacks/incremental_alter_configs_handler.rb +42 -0
  83. data/lib/rdkafka/callbacks/list_consumer_groups_handler.rb +39 -0
  84. data/lib/rdkafka/callbacks/list_offsets_handler.rb +42 -0
  85. data/lib/rdkafka/callbacks.rb +273 -52
  86. data/lib/rdkafka/clients.rb +81 -0
  87. data/lib/rdkafka/config.rb +333 -91
  88. data/lib/rdkafka/consumer/allocator.rb +38 -0
  89. data/lib/rdkafka/consumer/headers.rb +39 -25
  90. data/lib/rdkafka/consumer/message.rb +18 -20
  91. data/lib/rdkafka/consumer/partition.rb +15 -4
  92. data/lib/rdkafka/consumer/topic_partition_list.rb +82 -48
  93. data/lib/rdkafka/consumer.rb +765 -192
  94. data/lib/rdkafka/defaults.rb +123 -0
  95. data/lib/rdkafka/error.rb +40 -14
  96. data/lib/rdkafka/helpers/list_offsets.rb +127 -0
  97. data/lib/rdkafka/helpers/metadata.rb +29 -0
  98. data/lib/rdkafka/helpers/oauth.rb +95 -0
  99. data/lib/rdkafka/helpers/time.rb +19 -0
  100. data/lib/rdkafka/metadata.rb +138 -26
  101. data/lib/rdkafka/native_kafka.rb +142 -22
  102. data/lib/rdkafka/producer/delivery_handle.rb +27 -7
  103. data/lib/rdkafka/producer/delivery_report.rb +71 -4
  104. data/lib/rdkafka/producer/partitions_count_cache.rb +212 -0
  105. data/lib/rdkafka/producer.rb +422 -81
  106. data/lib/rdkafka/version.rb +6 -3
  107. data/lib/rdkafka.rb +73 -1
  108. data/package-lock.json +331 -0
  109. data/package.json +9 -0
  110. data/rdkafka.gemspec +78 -25
  111. data/renovate.json +111 -0
  112. metadata +114 -134
  113. data/.gitignore +0 -8
  114. data/.rspec +0 -1
  115. data/.semaphore/semaphore.yml +0 -27
  116. data/.yardopts +0 -2
  117. data/Gemfile +0 -5
  118. data/Guardfile +0 -19
  119. data/ext/README.md +0 -18
  120. data/spec/rdkafka/abstract_handle_spec.rb +0 -115
  121. data/spec/rdkafka/admin/create_topic_handle_spec.rb +0 -54
  122. data/spec/rdkafka/admin/create_topic_report_spec.rb +0 -18
  123. data/spec/rdkafka/admin/delete_topic_handle_spec.rb +0 -54
  124. data/spec/rdkafka/admin/delete_topic_report_spec.rb +0 -18
  125. data/spec/rdkafka/admin_spec.rb +0 -204
  126. data/spec/rdkafka/bindings_spec.rb +0 -136
  127. data/spec/rdkafka/callbacks_spec.rb +0 -22
  128. data/spec/rdkafka/config_spec.rb +0 -197
  129. data/spec/rdkafka/consumer/headers_spec.rb +0 -62
  130. data/spec/rdkafka/consumer/message_spec.rb +0 -141
  131. data/spec/rdkafka/consumer/partition_spec.rb +0 -59
  132. data/spec/rdkafka/consumer/topic_partition_list_spec.rb +0 -225
  133. data/spec/rdkafka/consumer_spec.rb +0 -1106
  134. data/spec/rdkafka/error_spec.rb +0 -91
  135. data/spec/rdkafka/metadata_spec.rb +0 -80
  136. data/spec/rdkafka/native_kafka_spec.rb +0 -124
  137. data/spec/rdkafka/producer/delivery_handle_spec.rb +0 -47
  138. data/spec/rdkafka/producer/delivery_report_spec.rb +0 -23
  139. data/spec/rdkafka/producer_spec.rb +0 -557
  140. data/spec/spec_helper.rb +0 -155
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Rdkafka::RdkafkaError do
6
- it "should raise a type error for a nil response" do
7
- expect {
8
- Rdkafka::RdkafkaError.new(nil)
9
- }.to raise_error TypeError
10
- end
11
-
12
- it "should create an error with a message prefix" do
13
- expect(Rdkafka::RdkafkaError.new(10, "message prefix").message_prefix).to eq "message prefix"
14
- end
15
-
16
- it "should create an error with a broker message" do
17
- expect(Rdkafka::RdkafkaError.new(10, broker_message: "broker message").broker_message).to eq "broker message"
18
- end
19
-
20
- describe "#code" do
21
- it "should handle an invalid response" do
22
- expect(Rdkafka::RdkafkaError.new(933975).code).to eq :err_933975?
23
- end
24
-
25
- it "should return error messages from rdkafka" do
26
- expect(Rdkafka::RdkafkaError.new(10).code).to eq :msg_size_too_large
27
- end
28
-
29
- it "should strip a leading underscore" do
30
- expect(Rdkafka::RdkafkaError.new(-191).code).to eq :partition_eof
31
- end
32
- end
33
-
34
- describe "#to_s" do
35
- it "should handle an invalid response" do
36
- expect(Rdkafka::RdkafkaError.new(933975).to_s).to eq "Err-933975? (err_933975?)"
37
- end
38
-
39
- it "should return error messages from rdkafka" do
40
- expect(Rdkafka::RdkafkaError.new(10).to_s).to eq "Broker: Message size too large (msg_size_too_large)"
41
- end
42
-
43
- it "should add the message prefix if present" do
44
- expect(Rdkafka::RdkafkaError.new(10, "Error explanation").to_s).to eq "Error explanation - Broker: Message size too large (msg_size_too_large)"
45
- end
46
- end
47
-
48
- describe "#message" do
49
- it "should handle an invalid response" do
50
- expect(Rdkafka::RdkafkaError.new(933975).message).to eq "Err-933975? (err_933975?)"
51
- end
52
-
53
- it "should return error messages from rdkafka" do
54
- expect(Rdkafka::RdkafkaError.new(10).message).to eq "Broker: Message size too large (msg_size_too_large)"
55
- end
56
-
57
- it "should add the message prefix if present" do
58
- expect(Rdkafka::RdkafkaError.new(10, "Error explanation").message).to eq "Error explanation - Broker: Message size too large (msg_size_too_large)"
59
- end
60
- end
61
-
62
- describe "#is_partition_eof?" do
63
- it "should be false when not partition eof" do
64
- expect(Rdkafka::RdkafkaError.new(933975).is_partition_eof?).to be false
65
- end
66
-
67
- it "should be true when partition eof" do
68
- expect(Rdkafka::RdkafkaError.new(-191).is_partition_eof?).to be true
69
- end
70
- end
71
-
72
- describe "#==" do
73
- subject { Rdkafka::RdkafkaError.new(10, "Error explanation") }
74
-
75
- it "should equal another error with the same content" do
76
- expect(subject).to eq Rdkafka::RdkafkaError.new(10, "Error explanation")
77
- end
78
-
79
- it "should not equal another error with a different error code" do
80
- expect(subject).not_to eq Rdkafka::RdkafkaError.new(20, "Error explanation")
81
- end
82
-
83
- it "should not equal another error with a different message" do
84
- expect(subject).not_to eq Rdkafka::RdkafkaError.new(10, "Different error explanation")
85
- end
86
-
87
- it "should not equal another error with no message" do
88
- expect(subject).not_to eq Rdkafka::RdkafkaError.new(10)
89
- end
90
- end
91
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "securerandom"
5
-
6
- describe Rdkafka::Metadata do
7
- let(:config) { rdkafka_consumer_config }
8
- let(:native_config) { config.send(:native_config) }
9
- let(:native_kafka) { config.send(:native_kafka, native_config, :rd_kafka_consumer) }
10
-
11
- after do
12
- Rdkafka::Bindings.rd_kafka_consumer_close(native_kafka)
13
- Rdkafka::Bindings.rd_kafka_destroy(native_kafka)
14
- end
15
-
16
- context "passing in a topic name" do
17
- context "that is non-existent topic" do
18
- let(:topic_name) { SecureRandom.uuid.to_s }
19
-
20
- it "raises an appropriate exception" do
21
- expect {
22
- described_class.new(native_kafka, topic_name)
23
- }.to raise_exception(Rdkafka::RdkafkaError, "Broker: Unknown topic or partition (unknown_topic_or_part)")
24
- end
25
- end
26
-
27
- context "that is one of our test topics" do
28
- subject { described_class.new(native_kafka, topic_name) }
29
- let(:topic_name) { "partitioner_test_topic" }
30
-
31
- it "#brokers returns our single broker" do
32
- expect(subject.brokers.length).to eq(1)
33
- expect(subject.brokers[0][:broker_id]).to eq(1)
34
- expect(subject.brokers[0][:broker_name]).to eq("localhost")
35
- expect(subject.brokers[0][:broker_port]).to eq(9092)
36
- end
37
-
38
- it "#topics returns data on our test topic" do
39
- expect(subject.topics.length).to eq(1)
40
- expect(subject.topics[0][:partition_count]).to eq(25)
41
- expect(subject.topics[0][:partitions].length).to eq(25)
42
- expect(subject.topics[0][:topic_name]).to eq(topic_name)
43
- end
44
- end
45
- end
46
-
47
- context "not passing in a topic name" do
48
- subject { described_class.new(native_kafka, topic_name) }
49
- let(:topic_name) { nil }
50
- let(:test_topics) {
51
- %w(consume_test_topic empty_test_topic load_test_topic produce_test_topic rake_test_topic watermarks_test_topic partitioner_test_topic)
52
- } # Test topics crated in spec_helper.rb
53
-
54
- it "#brokers returns our single broker" do
55
- expect(subject.brokers.length).to eq(1)
56
- expect(subject.brokers[0][:broker_id]).to eq(1)
57
- expect(subject.brokers[0][:broker_name]).to eq("localhost")
58
- expect(subject.brokers[0][:broker_port]).to eq(9092)
59
- end
60
-
61
- it "#topics returns data about all of our test topics" do
62
- result = subject.topics.map { |topic| topic[:topic_name] }
63
- expect(result).to include(*test_topics)
64
- end
65
- end
66
-
67
- context "when a non-zero error code is returned" do
68
- let(:topic_name) { SecureRandom.uuid.to_s }
69
-
70
- before do
71
- allow(Rdkafka::Bindings).to receive(:rd_kafka_metadata).and_return(-165)
72
- end
73
-
74
- it "creating the instance raises an exception" do
75
- expect {
76
- described_class.new(native_kafka, topic_name)
77
- }.to raise_error(Rdkafka::RdkafkaError, /Local: Required feature not supported by broker \(unsupported_feature\)/)
78
- end
79
- end
80
- end
@@ -1,124 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Rdkafka::NativeKafka do
6
- let(:config) { rdkafka_producer_config }
7
- let(:native) { config.send(:native_kafka, config.send(:native_config), :rd_kafka_producer) }
8
- let(:closing) { false }
9
- let(:thread) { double(Thread) }
10
-
11
- subject(:client) { described_class.new(native, run_polling_thread: true) }
12
-
13
- before do
14
- allow(Thread).to receive(:new).and_return(thread)
15
-
16
- allow(thread).to receive(:[]=).with(:closing, anything)
17
- allow(thread).to receive(:join)
18
- allow(thread).to receive(:abort_on_exception=).with(anything)
19
- end
20
-
21
- after { client.close }
22
-
23
- context "defaults" do
24
- it "sets the thread to abort on exception" do
25
- expect(thread).to receive(:abort_on_exception=).with(true)
26
-
27
- client
28
- end
29
-
30
- it "sets the thread `closing` flag to false" do
31
- expect(thread).to receive(:[]=).with(:closing, false)
32
-
33
- client
34
- end
35
- end
36
-
37
- context "the polling thread" do
38
- it "is created" do
39
- expect(Thread).to receive(:new)
40
-
41
- client
42
- end
43
- end
44
-
45
- it "exposes the inner client" do
46
- client.with_inner do |inner|
47
- expect(inner).to eq(native)
48
- end
49
- end
50
-
51
- context "when client was not yet closed (`nil`)" do
52
- it "is not closed" do
53
- expect(client.closed?).to eq(false)
54
- end
55
-
56
- context "and attempt to close" do
57
- it "calls the `destroy` binding" do
58
- expect(Rdkafka::Bindings).to receive(:rd_kafka_destroy).with(native).and_call_original
59
-
60
- client.close
61
- end
62
-
63
- it "indicates to the polling thread that it is closing" do
64
- expect(thread).to receive(:[]=).with(:closing, true)
65
-
66
- client.close
67
- end
68
-
69
- it "joins the polling thread" do
70
- expect(thread).to receive(:join)
71
-
72
- client.close
73
- end
74
-
75
- it "closes and unassign the native client" do
76
- client.close
77
-
78
- expect(client.closed?).to eq(true)
79
- end
80
- end
81
- end
82
-
83
- context "when client was already closed" do
84
- before { client.close }
85
-
86
- it "is closed" do
87
- expect(client.closed?).to eq(true)
88
- end
89
-
90
- context "and attempt to close again" do
91
- it "does not call the `destroy` binding" do
92
- expect(Rdkafka::Bindings).not_to receive(:rd_kafka_destroy_flags)
93
-
94
- client.close
95
- end
96
-
97
- it "does not indicate to the polling thread that it is closing" do
98
- expect(thread).not_to receive(:[]=).with(:closing, true)
99
-
100
- client.close
101
- end
102
-
103
- it "does not join the polling thread" do
104
- expect(thread).not_to receive(:join)
105
-
106
- client.close
107
- end
108
-
109
- it "does not close and unassign the native client again" do
110
- client.close
111
-
112
- expect(client.closed?).to eq(true)
113
- end
114
- end
115
- end
116
-
117
- it "provides a finalizer that closes the native kafka client" do
118
- expect(client.closed?).to eq(false)
119
-
120
- client.finalizer.call("some-ignored-object-id")
121
-
122
- expect(client.closed?).to eq(true)
123
- end
124
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Rdkafka::Producer::DeliveryHandle do
6
- let(:response) { 0 }
7
-
8
- subject do
9
- Rdkafka::Producer::DeliveryHandle.new.tap do |handle|
10
- handle[:pending] = pending_handle
11
- handle[:response] = response
12
- handle[:partition] = 2
13
- handle[:offset] = 100
14
- handle[:topic_name] = FFI::MemoryPointer.from_string("produce_test_topic")
15
- end
16
- end
17
-
18
- describe "#wait" do
19
- let(:pending_handle) { true }
20
-
21
- it "should wait until the timeout and then raise an error" do
22
- expect {
23
- subject.wait(max_wait_timeout: 0.1)
24
- }.to raise_error Rdkafka::Producer::DeliveryHandle::WaitTimeoutError, /delivery/
25
- end
26
-
27
- context "when not pending anymore and no error" do
28
- let(:pending_handle) { false }
29
-
30
- it "should return a delivery report" do
31
- report = subject.wait
32
-
33
- expect(report.partition).to eq(2)
34
- expect(report.offset).to eq(100)
35
- expect(report.topic_name).to eq("produce_test_topic")
36
- end
37
-
38
- it "should wait without a timeout" do
39
- report = subject.wait(max_wait_timeout: nil)
40
-
41
- expect(report.partition).to eq(2)
42
- expect(report.offset).to eq(100)
43
- expect(report.topic_name).to eq("produce_test_topic")
44
- end
45
- end
46
- end
47
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe Rdkafka::Producer::DeliveryReport do
6
- subject { Rdkafka::Producer::DeliveryReport.new(2, 100, "topic", -1) }
7
-
8
- it "should get the partition" do
9
- expect(subject.partition).to eq 2
10
- end
11
-
12
- it "should get the offset" do
13
- expect(subject.offset).to eq 100
14
- end
15
-
16
- it "should get the topic_name" do
17
- expect(subject.topic_name).to eq "topic"
18
- end
19
-
20
- it "should get the error" do
21
- expect(subject.error).to eq -1
22
- end
23
- end