rdkafka 0.12.0.beta.0 → 0.12.0.beta.3

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: a58b7e8b03dec32027bf3d9ec513a87e6bb0a8abf2f6598cd34a965bebce2dbb
4
- data.tar.gz: 603c985bd19a2213671b600680a748279e21d7b4aeb3f23a7f1efa16a5e1229c
3
+ metadata.gz: 1a6f8dfde957dbdc31ad2f229a6da70ef3023705bfc68e4414e896118b7df3c6
4
+ data.tar.gz: ed07422acb0268bb6483bda6eb0a93a8d75194c06589918e2d8a1cde5bf7ea5b
5
5
  SHA512:
6
- metadata.gz: 9e5a5bd4c911f93572d0f8be2e5f576b08ee0ff86ab773e9e7d9db1182002e62c1c57b03cfe6e7b686c9890c35f6fca811fe10daad3a0d4d57bd67a5340c7fa1
7
- data.tar.gz: 5fd3c57d9797f3b1f7c636f8190cee0b8cfc56f14daa03a2be21da6ff11fff1b7e00e233ab10a37b280b06ac2a197c155ebf1fdd6dfc8a97af9ce8bd38a341e1
6
+ metadata.gz: 8e51b05b0aa38d8d31ee0e8394f4d5a637ca8ef591fa2f0c76699ced276101902816f89c1c200ab45f02a13f68ed2fe35c961070c851c840e46986526ac1422a
7
+ data.tar.gz: f7414245c4ce729abe326a7fac4be7617a68615c3d4339888e22424bb0a49faa5077c2caf725453ab361f1f88afff7d1a7ff4928afcb433792983f2851484c12
data/lib/rdkafka/admin.rb CHANGED
@@ -90,7 +90,7 @@ module Rdkafka
90
90
  admin_options_ptr,
91
91
  queue_ptr
92
92
  )
93
- rescue Exception => err
93
+ rescue Exception
94
94
  CreateTopicHandle.remove(create_topic_handle.to_ptr.address)
95
95
  raise
96
96
  ensure
@@ -140,7 +140,7 @@ module Rdkafka
140
140
  admin_options_ptr,
141
141
  queue_ptr
142
142
  )
143
- rescue Exception => err
143
+ rescue Exception
144
144
  DeleteTopicHandle.remove(delete_topic_handle.to_ptr.address)
145
145
  raise
146
146
  ensure
@@ -246,14 +246,21 @@ module Rdkafka
246
246
  attach_function :rd_kafka_conf_set_dr_msg_cb, [:pointer, :delivery_cb], :void
247
247
 
248
248
  # Partitioner
249
- attach_function :rd_kafka_msg_partitioner_consistent_random, [:pointer, :pointer, :size_t, :int32, :pointer, :pointer], :int32
249
+ PARTITIONERS = %w(random consistent consistent_random murmur2 murmur2_random fnv1a fnv1a_random).each_with_object({}) do |name, hsh|
250
+ method_name = "rd_kafka_msg_partitioner_#{name}".to_sym
251
+ attach_function method_name, [:pointer, :pointer, :size_t, :int32, :pointer, :pointer], :int32
252
+ hsh[name] = method_name
253
+ end
250
254
 
251
- def self.partitioner(str, partition_count)
255
+ def self.partitioner(str, partition_count, partitioner_name = "consistent_random")
252
256
  # Return RD_KAFKA_PARTITION_UA(unassigned partition) when partition count is nil/zero.
253
257
  return -1 unless partition_count&.nonzero?
254
258
 
255
259
  str_ptr = FFI::MemoryPointer.from_string(str)
256
- rd_kafka_msg_partitioner_consistent_random(nil, str_ptr, str.size, partition_count, nil, nil)
260
+ method_name = PARTITIONERS.fetch(partitioner_name) do
261
+ raise Rdkafka::Config::ConfigError.new("Unknown partitioner: #{partitioner_name}")
262
+ end
263
+ public_send(method_name, nil, str_ptr, str.size, partition_count, nil, nil)
257
264
  end
258
265
 
259
266
  # Create Topics
@@ -179,7 +179,7 @@ module Rdkafka
179
179
  # Set callback to receive delivery reports on config
180
180
  Rdkafka::Bindings.rd_kafka_conf_set_dr_msg_cb(config, Rdkafka::Callbacks::DeliveryCallbackFunction)
181
181
  # Return producer with Kafka client
182
- Rdkafka::Producer.new(Rdkafka::Producer::Client.new(native_kafka(config, :rd_kafka_producer))).tap do |producer|
182
+ Rdkafka::Producer.new(Rdkafka::Producer::Client.new(native_kafka(config, :rd_kafka_producer)), self[:partitioner]).tap do |producer|
183
183
  opaque.producer = producer
184
184
  end
185
185
  end
@@ -10,8 +10,9 @@ module Rdkafka
10
10
  attr_reader :delivery_callback
11
11
 
12
12
  # @private
13
- def initialize(client)
13
+ def initialize(client, partitioner_name)
14
14
  @client = client
15
+ @partitioner_name = partitioner_name || "consistent_random"
15
16
 
16
17
  # Makes sure, that the producer gets closed before it gets GCed by Ruby
17
18
  ObjectSpace.define_finalizer(self, client.finalizer)
@@ -85,7 +86,7 @@ module Rdkafka
85
86
  if partition_key
86
87
  partition_count = partition_count(topic)
87
88
  # If the topic is not present, set to -1
88
- partition = Rdkafka::Bindings.partitioner(partition_key, partition_count) if partition_count
89
+ partition = Rdkafka::Bindings.partitioner(partition_key, partition_count, @partitioner_name) if partition_count
89
90
  end
90
91
 
91
92
  # If partition is nil, use -1 to let librdafka set the partition randomly or
@@ -1,5 +1,5 @@
1
1
  module Rdkafka
2
- VERSION = "0.12.0.beta.0"
3
- LIBRDKAFKA_VERSION = "1.8.2"
4
- LIBRDKAFKA_SOURCE_SHA256 = "6a747d293a7a4613bd2897e28e8791476fbe1ae7361f2530a876e0fd483482a6"
2
+ VERSION = "0.12.0.beta.3"
3
+ LIBRDKAFKA_VERSION = "1.9.0-RC2"
4
+ LIBRDKAFKA_SOURCE_SHA256 = "f38c7007d01c489c7b743d200a6760678f43b171b36886c4dda39d4a8d5aab59"
5
5
  end
@@ -76,6 +76,13 @@ describe Rdkafka::Bindings do
76
76
  result_2 = (Zlib.crc32(partition_key) % partition_count)
77
77
  expect(result_1).to eq(result_2)
78
78
  end
79
+
80
+ it "should return the partition calculated by the specified partitioner" do
81
+ result_1 = Rdkafka::Bindings.partitioner(partition_key, partition_count, "murmur2")
82
+ ptr = FFI::MemoryPointer.from_string(partition_key)
83
+ result_2 = Rdkafka::Bindings.rd_kafka_msg_partitioner_murmur2(nil, ptr, partition_key.size, partition_count, nil, nil)
84
+ expect(result_1).to eq(result_2)
85
+ end
79
86
  end
80
87
 
81
88
  describe "stats callback" do
@@ -241,7 +241,7 @@ describe Rdkafka::Consumer do
241
241
 
242
242
  it "should return the assignment when subscribed" do
243
243
  # Make sure there's a message
244
- report = producer.produce(
244
+ producer.produce(
245
245
  topic: "consume_test_topic",
246
246
  payload: "payload 1",
247
247
  key: "key 1",
@@ -272,7 +272,7 @@ describe Rdkafka::Consumer do
272
272
  it "should close a consumer" do
273
273
  consumer.subscribe("consume_test_topic")
274
274
  100.times do |i|
275
- report = producer.produce(
275
+ producer.produce(
276
276
  topic: "consume_test_topic",
277
277
  payload: "payload #{i}",
278
278
  key: "key #{i}",
@@ -289,7 +289,7 @@ describe Rdkafka::Consumer do
289
289
  describe "#commit, #committed and #store_offset" do
290
290
  # Make sure there's a stored offset
291
291
  let!(:report) do
292
- report = producer.produce(
292
+ producer.produce(
293
293
  topic: "consume_test_topic",
294
294
  payload: "payload 1",
295
295
  key: "key 1",
@@ -831,7 +831,6 @@ describe Rdkafka::Consumer do
831
831
  )
832
832
  consumer = config.consumer
833
833
  consumer.subscribe(topic_name)
834
- loop_count = 0
835
834
  batches_yielded = []
836
835
  exceptions_yielded = []
837
836
  each_batch_iterations = 0
@@ -875,7 +874,6 @@ describe Rdkafka::Consumer do
875
874
  )
876
875
  consumer = config.consumer
877
876
  consumer.subscribe(topic_name)
878
- loop_count = 0
879
877
  batches_yielded = []
880
878
  exceptions_yielded = []
881
879
  each_batch_iterations = 0
@@ -1,15 +1,16 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rdkafka::Producer::Client do
4
- let(:native) { double }
4
+ let(:config) { rdkafka_producer_config }
5
+ let(:native) { config.send(:native_kafka, config.send(:native_config), :rd_kafka_producer) }
5
6
  let(:closing) { false }
6
7
  let(:thread) { double(Thread) }
7
8
 
8
9
  subject(:client) { described_class.new(native) }
9
10
 
10
11
  before do
11
- allow(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(native, 250)
12
- allow(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(native).and_return(0)
12
+ allow(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(instance_of(FFI::Pointer), 250).and_call_original
13
+ allow(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(instance_of(FFI::Pointer)).and_return(0).and_call_original
13
14
  allow(Rdkafka::Bindings).to receive(:rd_kafka_destroy)
14
15
  allow(Thread).to receive(:new).and_return(thread)
15
16
 
@@ -41,13 +42,13 @@ describe Rdkafka::Producer::Client do
41
42
 
42
43
  it "polls the native with default 250ms timeout" do
43
44
  polling_loop_expects do
44
- expect(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(native, 250)
45
+ expect(Rdkafka::Bindings).to receive(:rd_kafka_poll).with(instance_of(FFI::Pointer), 250).at_least(:once)
45
46
  end
46
47
  end
47
48
 
48
49
  it "check the out queue of native client" do
49
50
  polling_loop_expects do
50
- expect(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(native)
51
+ expect(Rdkafka::Bindings).to receive(:rd_kafka_outq_len).with(native).at_least(:once)
51
52
  end
52
53
  end
53
54
  end
@@ -376,13 +376,9 @@ describe Rdkafka::Producer do
376
376
  end
377
377
  end
378
378
 
379
- it "should produce a message in a forked process" do
379
+ it "should produce a message in a forked process", skip: defined?(JRUBY_VERSION) && "Kernel#fork is not available" do
380
380
  # Fork, produce a message, send the report over a pipe and
381
381
  # wait for and check the message in the main process.
382
-
383
- # Kernel#fork is not available in JRuby
384
- skip if defined?(JRUBY_VERSION)
385
-
386
382
  reader, writer = IO.pipe
387
383
 
388
384
  fork do
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.12.0.beta.0
4
+ version: 0.12.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thijs Cadier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -206,7 +206,7 @@ homepage: https://github.com/thijsc/rdkafka-ruby
206
206
  licenses:
207
207
  - MIT
208
208
  metadata: {}
209
- post_install_message:
209
+ post_install_message:
210
210
  rdoc_options: []
211
211
  require_paths:
212
212
  - lib
@@ -221,8 +221,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  - !ruby/object:Gem::Version
222
222
  version: 1.3.1
223
223
  requirements: []
224
- rubygems_version: 3.1.4
225
- signing_key:
224
+ rubygems_version: 3.0.3
225
+ signing_key:
226
226
  specification_version: 4
227
227
  summary: The rdkafka gem is a modern Kafka client library for Ruby based on librdkafka.
228
228
  It wraps the production-ready C client using the ffi gem and targets Kafka 1.0+