rdkafka 0.12.0.beta.4 → 0.12.1
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/CHANGELOG.md +3 -0
- data/dist/librdkafka_1.9.0.tar.gz +0 -0
- data/ext/Rakefile +56 -27
- data/lib/rdkafka/callbacks.rb +1 -1
- data/lib/rdkafka/config.rb +2 -2
- data/lib/rdkafka/producer.rb +19 -3
- data/lib/rdkafka/version.rb +3 -3
- data/spec/rdkafka/producer_spec.rb +51 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a75568ae9eddc2f80921c43835725e535ddc0c72d5ff931018d08dc8737a6c12
|
4
|
+
data.tar.gz: 7f65353380913d15603728f3fb3c4355ac87b46f380b762ad40a534f981df1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b802ae224948f5e51c83025cf5a8dd937058c34a336d10f2d4cc3f8dfcebfdb8cdcfc73d92dab169f1f4fac412e1ce424412584f7398af65371bcbb6e271f0e5
|
7
|
+
data.tar.gz: c668c6dfa9f7aadd35614c36cb9ad259b1e8519b949f32116f306e56d61719292a3e49bced751d1abcf7065fab713694756cec8777236b8f61c615dc9745e2e0
|
data/CHANGELOG.md
CHANGED
Binary file
|
data/ext/Rakefile
CHANGED
@@ -1,38 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('../../lib/rdkafka/version', __FILE__)
|
2
|
-
require "mini_portile2"
|
3
4
|
require "fileutils"
|
4
5
|
require "open-uri"
|
5
6
|
|
6
7
|
task :default => :clean do
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
12
|
-
if
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# For nix users, nix can't locate the file paths because the packages it's requiring aren't managed by the system but are
|
9
|
+
# managed by nix itself, so using the normal file paths doesn't work for nix users.
|
10
|
+
#
|
11
|
+
# Mini_portile causes an issue because it's dependencies are downloaded on the fly and therefore don't exist/aren't
|
12
|
+
# accessible in the nix environment
|
13
|
+
if ENV.fetch('RDKAFKA_EXT_PATH', '').empty?
|
14
|
+
# Download and compile librdkafka if RDKAFKA_EXT_PATH is not set
|
15
|
+
require "mini_portile2"
|
16
|
+
recipe = MiniPortile.new("librdkafka", Rdkafka::LIBRDKAFKA_VERSION)
|
17
|
+
|
18
|
+
# Use default homebrew openssl if we're on mac and the directory exists
|
19
|
+
# and each of flags is not empty
|
20
|
+
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?("#{homebrew_prefix = %x(brew --prefix openssl).strip}")
|
21
|
+
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV["CPPFLAGS"]
|
22
|
+
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV["LDFLAGS"]
|
23
|
+
end
|
24
|
+
|
25
|
+
releases = File.expand_path(File.join(File.dirname(__FILE__), '../dist'))
|
26
|
+
|
27
|
+
recipe.files << {
|
28
|
+
:url => "file://#{releases}/librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz",
|
29
|
+
:sha256 => Rdkafka::LIBRDKAFKA_SOURCE_SHA256
|
30
|
+
}
|
31
|
+
recipe.configure_options = ["--host=#{recipe.host}"]
|
16
32
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
# Disable using libc regex engine in favor of the embedded one
|
34
|
+
# The default regex engine of librdkafka does not always work exactly as most of the users
|
35
|
+
# would expect, hence this flag allows for changing it to the other one
|
36
|
+
if ENV.key?('RDKAFKA_DISABLE_REGEX_EXT')
|
37
|
+
recipe.configure_options << '--disable-regex-ext'
|
38
|
+
end
|
39
|
+
|
40
|
+
recipe.cook
|
41
|
+
# Move dynamic library we're interested in
|
42
|
+
if recipe.host.include?('darwin')
|
43
|
+
from_extension = '1.dylib'
|
44
|
+
to_extension = 'dylib'
|
45
|
+
else
|
46
|
+
from_extension = 'so.1'
|
47
|
+
to_extension = 'so'
|
48
|
+
end
|
49
|
+
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
|
50
|
+
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
|
51
|
+
# Cleanup files created by miniportile we don't need in the gem
|
52
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
|
53
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
|
27
54
|
else
|
28
|
-
|
29
|
-
|
55
|
+
# Otherwise, copy existing libraries to ./ext
|
56
|
+
if ENV['RDKAFKA_EXT_PATH'].nil? || ENV['RDKAFKA_EXT_PATH'].empty?
|
57
|
+
raise "RDKAFKA_EXT_PATH must be set in your nix config when running under nix"
|
58
|
+
end
|
59
|
+
files = [
|
60
|
+
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.dylib'),
|
61
|
+
File.join(ENV['RDKAFKA_EXT_PATH'], 'lib', 'librdkafka.so')
|
62
|
+
]
|
63
|
+
files.each { |ext| FileUtils.cp(ext, File.dirname(__FILE__)) if File.exist?(ext) }
|
30
64
|
end
|
31
|
-
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
|
32
|
-
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
|
33
|
-
# Cleanup files created by miniportile we don't need in the gem
|
34
|
-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
|
35
|
-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
|
36
65
|
end
|
37
66
|
|
38
67
|
task :clean do
|
data/lib/rdkafka/callbacks.rb
CHANGED
@@ -97,7 +97,7 @@ module Rdkafka
|
|
97
97
|
delivery_handle[:pending] = false
|
98
98
|
# Call delivery callback on opaque
|
99
99
|
if opaque = Rdkafka::Config.opaques[opaque_ptr.to_i]
|
100
|
-
opaque.call_delivery_callback(Rdkafka::Producer::DeliveryReport.new(message[:partition], message[:offset], message[:err]))
|
100
|
+
opaque.call_delivery_callback(Rdkafka::Producer::DeliveryReport.new(message[:partition], message[:offset], message[:err]), delivery_handle)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/lib/rdkafka/config.rb
CHANGED
@@ -278,8 +278,8 @@ module Rdkafka
|
|
278
278
|
attr_accessor :producer
|
279
279
|
attr_accessor :consumer_rebalance_listener
|
280
280
|
|
281
|
-
def call_delivery_callback(delivery_handle)
|
282
|
-
producer.call_delivery_callback(delivery_handle) if producer
|
281
|
+
def call_delivery_callback(delivery_report, delivery_handle)
|
282
|
+
producer.call_delivery_callback(delivery_report, delivery_handle) if producer
|
283
283
|
end
|
284
284
|
|
285
285
|
def call_on_partitions_assigned(consumer, list)
|
data/lib/rdkafka/producer.rb
CHANGED
@@ -9,6 +9,12 @@ module Rdkafka
|
|
9
9
|
# @return [Proc, nil]
|
10
10
|
attr_reader :delivery_callback
|
11
11
|
|
12
|
+
# @private
|
13
|
+
# Returns the number of arguments accepted by the callback, by default this is nil.
|
14
|
+
#
|
15
|
+
# @return [Integer, nil]
|
16
|
+
attr_reader :delivery_callback_arity
|
17
|
+
|
12
18
|
# @private
|
13
19
|
def initialize(client, partitioner_name)
|
14
20
|
@client = client
|
@@ -19,7 +25,7 @@ module Rdkafka
|
|
19
25
|
end
|
20
26
|
|
21
27
|
# Set a callback that will be called every time a message is successfully produced.
|
22
|
-
# The callback is called with a {DeliveryReport}
|
28
|
+
# The callback is called with a {DeliveryReport} and {DeliveryHandle}
|
23
29
|
#
|
24
30
|
# @param callback [Proc, #call] The callback
|
25
31
|
#
|
@@ -27,6 +33,7 @@ module Rdkafka
|
|
27
33
|
def delivery_callback=(callback)
|
28
34
|
raise TypeError.new("Callback has to be callable") unless callback.respond_to?(:call)
|
29
35
|
@delivery_callback = callback
|
36
|
+
@delivery_callback_arity = arity(callback)
|
30
37
|
end
|
31
38
|
|
32
39
|
# Close this producer and wait for the internal poll queue to empty.
|
@@ -151,8 +158,17 @@ module Rdkafka
|
|
151
158
|
end
|
152
159
|
|
153
160
|
# @private
|
154
|
-
def call_delivery_callback(delivery_handle)
|
155
|
-
|
161
|
+
def call_delivery_callback(delivery_report, delivery_handle)
|
162
|
+
return unless @delivery_callback
|
163
|
+
|
164
|
+
args = [delivery_report, delivery_handle].take(@delivery_callback_arity)
|
165
|
+
@delivery_callback.call(*args)
|
166
|
+
end
|
167
|
+
|
168
|
+
def arity(callback)
|
169
|
+
return callback.arity if callback.respond_to?(:arity)
|
170
|
+
|
171
|
+
callback.method(:call).arity
|
156
172
|
end
|
157
173
|
|
158
174
|
def closed_producer_check(method)
|
data/lib/rdkafka/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rdkafka
|
2
|
-
VERSION = "0.12.
|
3
|
-
LIBRDKAFKA_VERSION = "1.9.0
|
4
|
-
LIBRDKAFKA_SOURCE_SHA256 = "
|
2
|
+
VERSION = "0.12.1"
|
3
|
+
LIBRDKAFKA_VERSION = "1.9.0"
|
4
|
+
LIBRDKAFKA_SOURCE_SHA256 = "59b6088b69ca6cf278c3f9de5cd6b7f3fd604212cd1c59870bc531c54147e889"
|
5
5
|
end
|
@@ -49,6 +49,27 @@ describe Rdkafka::Producer do
|
|
49
49
|
# Callback should have been called
|
50
50
|
expect(@callback_called).to be true
|
51
51
|
end
|
52
|
+
|
53
|
+
it "should provide handle" do
|
54
|
+
@callback_handle = nil
|
55
|
+
|
56
|
+
producer.delivery_callback = lambda { |_, handle| @callback_handle = handle }
|
57
|
+
|
58
|
+
# Produce a message
|
59
|
+
handle = producer.produce(
|
60
|
+
topic: "produce_test_topic",
|
61
|
+
payload: "payload",
|
62
|
+
key: "key"
|
63
|
+
)
|
64
|
+
|
65
|
+
# Wait for it to be delivered
|
66
|
+
handle.wait(max_wait_timeout: 15)
|
67
|
+
|
68
|
+
# Join the producer thread.
|
69
|
+
producer.close
|
70
|
+
|
71
|
+
expect(handle).to be @callback_handle
|
72
|
+
end
|
52
73
|
end
|
53
74
|
|
54
75
|
context "with a callable object" do
|
@@ -93,6 +114,36 @@ describe Rdkafka::Producer do
|
|
93
114
|
expect(called_report.first.partition).to eq 1
|
94
115
|
expect(called_report.first.offset).to be >= 0
|
95
116
|
end
|
117
|
+
|
118
|
+
it "should provide handle" do
|
119
|
+
callback_handles = []
|
120
|
+
callback = Class.new do
|
121
|
+
def initialize(callback_handles)
|
122
|
+
@callback_handles = callback_handles
|
123
|
+
end
|
124
|
+
|
125
|
+
def call(_, handle)
|
126
|
+
@callback_handles << handle
|
127
|
+
end
|
128
|
+
end
|
129
|
+
producer.delivery_callback = callback.new(callback_handles)
|
130
|
+
|
131
|
+
# Produce a message
|
132
|
+
handle = producer.produce(
|
133
|
+
topic: "produce_test_topic",
|
134
|
+
payload: "payload",
|
135
|
+
key: "key"
|
136
|
+
)
|
137
|
+
|
138
|
+
# Wait for it to be delivered
|
139
|
+
handle.wait(max_wait_timeout: 15)
|
140
|
+
|
141
|
+
# Join the producer thread.
|
142
|
+
producer.close
|
143
|
+
|
144
|
+
# Callback should have been called
|
145
|
+
expect(handle).to be callback_handles.first
|
146
|
+
end
|
96
147
|
end
|
97
148
|
|
98
149
|
it "should not accept a callback that's not callable" 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.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thijs Cadier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- README.md
|
157
157
|
- Rakefile
|
158
158
|
- bin/console
|
159
|
+
- dist/librdkafka_1.9.0.tar.gz
|
159
160
|
- docker-compose.yml
|
160
161
|
- ext/README.md
|
161
162
|
- ext/Rakefile
|
@@ -217,11 +218,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
218
|
version: '2.6'
|
218
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
220
|
requirements:
|
220
|
-
- - "
|
221
|
+
- - ">="
|
221
222
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
223
|
+
version: '0'
|
223
224
|
requirements: []
|
224
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.5.14
|
225
226
|
signing_key:
|
226
227
|
specification_version: 4
|
227
228
|
summary: The rdkafka gem is a modern Kafka client library for Ruby based on librdkafka.
|