rdkafka 0.9.0 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22bda74a815bebd487179ac5ec3faa4566752f2c87945ca5c461c427633daf1f
4
- data.tar.gz: '0802ca4118ed248fa11226a2c1b2140d073d230c02e3696a03e462fe59cb129e'
3
+ metadata.gz: 9f954490d858591f12e5a7fc1fed82e1b5c6b42049c5ed66d2d76bb352e03a7f
4
+ data.tar.gz: 0ae8cbac09963d52a3075cece9e0bf6c5895e31f87995d7997ee7f04e52a10c8
5
5
  SHA512:
6
- metadata.gz: 4d3b7042fa2290386d4feaaa01c4289bc858042d66806157066257f282c84db459e80e32a2613efd3452a46c63faaff7fad9f110fb153c3385cef00fb6017f27
7
- data.tar.gz: e431a320535df8293e099e1b25bf0e6da68caf9a641621faf847dd206093dd9973b41f03f95412c43a740b50a0ef70e7caad418ff20c07218f19342d1cb3826a
6
+ metadata.gz: 33d43862b6b7cee1a3284221f75fae0c6bdfa6df4faa4396378c96e34a8f1a2395202dd01d6a5f2baac5557010505f548e7862bdd14202de6b3f85c77ca95309
7
+ data.tar.gz: 22d6243a853bfd630497eab13a8b6823f1a1d4a358aee53a98e68e5a0255f5ca68932db6d261cbad34dadeca5854522d8fceb15b43004ce8719a1d5d9aa3e9bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.10.0
2
+ * Upgrade librdkafka to 1.5.0
3
+ * Add error callback config
4
+
1
5
  # 0.9.0
2
6
  * Fixes for Ruby 3.0
3
7
  * Allow any callable object for callbacks (gremerritt)
@@ -108,6 +108,8 @@ module Rdkafka
108
108
  attach_function :rd_kafka_conf_set_opaque, [:pointer, :pointer], :void
109
109
  callback :stats_cb, [:pointer, :string, :int, :pointer], :int
110
110
  attach_function :rd_kafka_conf_set_stats_cb, [:pointer, :stats_cb], :void
111
+ callback :error_cb, [:pointer, :int, :string, :pointer], :void
112
+ attach_function :rd_kafka_conf_set_error_cb, [:pointer, :error_cb], :void
111
113
 
112
114
  # Log queue
113
115
  attach_function :rd_kafka_set_log_queue, [:pointer, :pointer], :void
@@ -146,6 +148,15 @@ module Rdkafka
146
148
  0
147
149
  end
148
150
 
151
+ ErrorCallback = FFI::Function.new(
152
+ :void, [:pointer, :int, :string, :pointer]
153
+ ) do |_client_prr, err_code, reason, _opaque|
154
+ if Rdkafka::Config.error_callback
155
+ error = Rdkafka::RdkafkaError.new(err_code, broker_message: reason)
156
+ Rdkafka::Config.error_callback.call(error)
157
+ end
158
+ end
159
+
149
160
  # Handle
150
161
 
151
162
  enum :kafka_type, [
@@ -10,6 +10,8 @@ module Rdkafka
10
10
  # @private
11
11
  @@statistics_callback = nil
12
12
  # @private
13
+ @@error_callback = nil
14
+ # @private
13
15
  @@opaques = {}
14
16
  # @private
15
17
  @@log_queue = Queue.new
@@ -28,6 +30,7 @@ module Rdkafka
28
30
  @@logger
29
31
  end
30
32
 
33
+
31
34
  # Returns a queue whose contents will be passed to the configured logger. Each entry
32
35
  # should follow the format [Logger::Severity, String]. The benefit over calling the
33
36
  # logger directly is that this is safe to use from trap contexts.
@@ -66,6 +69,25 @@ module Rdkafka
66
69
  @@statistics_callback
67
70
  end
68
71
 
72
+ # Set a callback that will be called every time the underlying client emits an error.
73
+ # If this callback is not set, global errors such as brokers becoming unavailable will only be sent to the logger, as defined by librdkafka.
74
+ # The callback is called with an instance of RdKafka::Error.
75
+ #
76
+ # @param callback [Proc, #call] The callback
77
+ #
78
+ # @return [nil]
79
+ def self.error_callback=(callback)
80
+ raise TypeError.new("Callback has to be callable") unless callback.respond_to?(:call)
81
+ @@error_callback = callback
82
+ end
83
+
84
+ # Returns the current error callback, by default this is nil.
85
+ #
86
+ # @return [Proc, nil]
87
+ def self.error_callback
88
+ @@error_callback
89
+ end
90
+
69
91
  # @private
70
92
  def self.opaques
71
93
  @@opaques
@@ -221,6 +243,9 @@ module Rdkafka
221
243
 
222
244
  # Set stats callback
223
245
  Rdkafka::Bindings.rd_kafka_conf_set_stats_cb(config, Rdkafka::Bindings::StatsCallback)
246
+
247
+ # Set error callback
248
+ Rdkafka::Bindings.rd_kafka_conf_set_error_cb(config, Rdkafka::Bindings::ErrorCallback)
224
249
  end
225
250
  end
226
251
 
@@ -1,3 +1,5 @@
1
+ require "securerandom"
2
+
1
3
  module Rdkafka
2
4
  # A producer for Kafka messages. To create a producer set up a {Config} and call {Config#producer producer} on that.
3
5
  class Producer
@@ -9,11 +11,12 @@ module Rdkafka
9
11
 
10
12
  # @private
11
13
  def initialize(native_kafka)
14
+ @id = SecureRandom.uuid
12
15
  @closing = false
13
16
  @native_kafka = native_kafka
14
17
 
15
18
  # Makes sure, that the producer gets closed before it gets GCed by Ruby
16
- ObjectSpace.define_finalizer(self, proc { close })
19
+ ObjectSpace.define_finalizer(@id, proc { close })
17
20
 
18
21
  # Start thread to poll client for delivery callbacks
19
22
  @polling_thread = Thread.new do
@@ -41,6 +44,8 @@ module Rdkafka
41
44
 
42
45
  # Close this producer and wait for the internal poll queue to empty.
43
46
  def close
47
+ ObjectSpace.undefine_finalizer(@id)
48
+
44
49
  return unless @native_kafka
45
50
 
46
51
  # Indicate to polling thread that we're closing
@@ -1,5 +1,5 @@
1
1
  module Rdkafka
2
- VERSION = "0.9.0"
3
- LIBRDKAFKA_VERSION = "1.4.0"
4
- LIBRDKAFKA_SOURCE_SHA256 = "ae27ea3f3d0d32d29004e7f709efbba2666c5383a107cc45b3a1949486b2eb84"
2
+ VERSION = "0.10.0"
3
+ LIBRDKAFKA_VERSION = "1.5.0"
4
+ LIBRDKAFKA_SOURCE_SHA256 = "f7fee59fdbf1286ec23ef0b35b2dfb41031c8727c90ced6435b8cf576f23a656"
5
5
  end
@@ -100,4 +100,28 @@ describe Rdkafka::Bindings do
100
100
  end
101
101
  end
102
102
  end
103
+
104
+ describe "error callback" do
105
+ context "without an error callback" do
106
+ it "should do nothing" do
107
+ expect {
108
+ Rdkafka::Bindings::ErrorCallback.call(nil, 1, "error", nil)
109
+ }.not_to raise_error
110
+ end
111
+ end
112
+
113
+ context "with an error callback" do
114
+ before do
115
+ Rdkafka::Config.error_callback = lambda do |error|
116
+ $received_error = error
117
+ end
118
+ end
119
+
120
+ it "should call the error callback with an Rdkafka::Error" do
121
+ Rdkafka::Bindings::ErrorCallback.call(nil, 8, "Broker not available", nil)
122
+ expect($received_error.code).to eq(:broker_not_available)
123
+ expect($received_error.broker_message).to eq("Broker not available")
124
+ end
125
+ end
126
+ end
103
127
  end
@@ -64,6 +64,37 @@ describe Rdkafka::Config do
64
64
  end
65
65
  end
66
66
 
67
+ context "error callback" do
68
+ context "with a proc/lambda" do
69
+ it "should set the callback" do
70
+ expect {
71
+ Rdkafka::Config.error_callback = lambda do |error|
72
+ puts error
73
+ end
74
+ }.not_to raise_error
75
+ expect(Rdkafka::Config.error_callback).to respond_to :call
76
+ end
77
+ end
78
+
79
+ context "with a callable object" do
80
+ it "should set the callback" do
81
+ callback = Class.new do
82
+ def call(stats); end
83
+ end
84
+ expect {
85
+ Rdkafka::Config.error_callback = callback.new
86
+ }.not_to raise_error
87
+ expect(Rdkafka::Config.error_callback).to respond_to :call
88
+ end
89
+ end
90
+
91
+ it "should not accept a callback that's not callable" do
92
+ expect {
93
+ Rdkafka::Config.error_callback = 'a string'
94
+ }.to raise_error(TypeError)
95
+ end
96
+ end
97
+
67
98
  context "configuration" do
68
99
  it "should store configuration" do
69
100
  config = Rdkafka::Config.new
@@ -724,6 +724,8 @@ describe Rdkafka::Consumer do
724
724
  #
725
725
  # This is, in effect, an integration test and the subsequent specs are
726
726
  # unit tests.
727
+ create_topic_handle = rdkafka_config.admin.create_topic(topic_name, 1, 1)
728
+ create_topic_handle.wait(max_wait_timeout: 15.0)
727
729
  consumer.subscribe(topic_name)
728
730
  produce_n 42
729
731
  all_yields = []
@@ -777,6 +779,8 @@ describe Rdkafka::Consumer do
777
779
  end
778
780
 
779
781
  it "should yield [] if nothing is received before the timeout" do
782
+ create_topic_handle = rdkafka_config.admin.create_topic(topic_name, 1, 1)
783
+ create_topic_handle.wait(max_wait_timeout: 15.0)
780
784
  consumer.subscribe(topic_name)
781
785
  consumer.each_batch do |batch|
782
786
  expect(batch).to eq([])
@@ -18,7 +18,7 @@ describe Rdkafka::Metadata do
18
18
  it "raises an appropriate exception" do
19
19
  expect {
20
20
  described_class.new(native_kafka, topic_name)
21
- }.to raise_exception(Rdkafka::RdkafkaError, "Broker: Leader not available (leader_not_available)")
21
+ }.to raise_exception(Rdkafka::RdkafkaError, "Broker: Unknown topic or partition (unknown_topic_or_part)")
22
22
  end
23
23
  end
24
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdkafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  requirements: []
190
- rubygems_version: 3.2.3
190
+ rubygems_version: 3.1.4
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: The rdkafka gem is a modern Kafka client library for Ruby based on librdkafka.