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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +388 -111
- data/{LICENSE → MIT-LICENSE} +2 -1
- data/README.md +90 -43
- data/Rakefile +21 -23
- data/bin/verify_kafka_warnings +44 -0
- data/dist/librdkafka-2.15.1.tar.gz +0 -0
- data/dist/patches/rdkafka_global_init.patch +15 -0
- data/docker-compose-ssl.yml +39 -0
- data/docker-compose.yml +22 -17
- data/ext/Rakefile +97 -30
- data/lib/rdkafka/abstract_handle.rb +113 -34
- data/lib/rdkafka/admin/acl_binding_result.rb +51 -0
- data/lib/rdkafka/admin/alter_consumer_group_offsets_handle.rb +31 -0
- data/lib/rdkafka/admin/alter_consumer_group_offsets_report.rb +50 -0
- data/lib/rdkafka/admin/config_binding_result.rb +30 -0
- data/lib/rdkafka/admin/config_resource_binding_result.rb +19 -0
- data/lib/rdkafka/admin/create_acl_handle.rb +32 -0
- data/lib/rdkafka/admin/create_acl_report.rb +26 -0
- data/lib/rdkafka/admin/create_partitions_handle.rb +28 -0
- data/lib/rdkafka/admin/create_partitions_report.rb +7 -0
- data/lib/rdkafka/admin/create_topic_handle.rb +8 -7
- data/lib/rdkafka/admin/create_topic_report.rb +4 -1
- data/lib/rdkafka/admin/delete_acl_handle.rb +31 -0
- data/lib/rdkafka/admin/delete_acl_report.rb +25 -0
- data/lib/rdkafka/admin/delete_consumer_group_offsets_handle.rb +31 -0
- data/lib/rdkafka/admin/delete_consumer_group_offsets_report.rb +50 -0
- data/lib/rdkafka/admin/delete_groups_handle.rb +31 -0
- data/lib/rdkafka/admin/delete_groups_report.rb +27 -0
- data/lib/rdkafka/admin/delete_records_handle.rb +31 -0
- data/lib/rdkafka/admin/delete_records_report.rb +25 -0
- data/lib/rdkafka/admin/delete_topic_handle.rb +8 -7
- data/lib/rdkafka/admin/delete_topic_report.rb +4 -1
- data/lib/rdkafka/admin/describe_acl_handle.rb +31 -0
- data/lib/rdkafka/admin/describe_acl_report.rb +27 -0
- data/lib/rdkafka/admin/describe_cluster_handle.rb +31 -0
- data/lib/rdkafka/admin/describe_cluster_report.rb +48 -0
- data/lib/rdkafka/admin/describe_configs_handle.rb +30 -0
- data/lib/rdkafka/admin/describe_configs_report.rb +56 -0
- data/lib/rdkafka/admin/describe_consumer_groups_handle.rb +31 -0
- data/lib/rdkafka/admin/describe_consumer_groups_report.rb +151 -0
- data/lib/rdkafka/admin/describe_result_parsing.rb +47 -0
- data/lib/rdkafka/admin/describe_topics_handle.rb +31 -0
- data/lib/rdkafka/admin/describe_topics_report.rb +118 -0
- data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +30 -0
- data/lib/rdkafka/admin/incremental_alter_configs_report.rb +56 -0
- data/lib/rdkafka/admin/list_consumer_groups_handle.rb +31 -0
- data/lib/rdkafka/admin/list_consumer_groups_report.rb +83 -0
- data/lib/rdkafka/admin/list_offsets_handle.rb +31 -0
- data/lib/rdkafka/admin/list_offsets_report.rb +54 -0
- data/lib/rdkafka/admin.rb +1381 -38
- data/lib/rdkafka/bindings/admin/acls.rb +85 -0
- data/lib/rdkafka/bindings/admin/configs.rb +37 -0
- data/lib/rdkafka/bindings/admin/list_offsets.rb +26 -0
- data/lib/rdkafka/bindings/admin.rb +197 -0
- data/lib/rdkafka/bindings/callbacks.rb +100 -0
- data/lib/rdkafka/bindings/configuration.rb +50 -0
- data/lib/rdkafka/bindings/consumer.rb +83 -0
- data/lib/rdkafka/bindings/errors.rb +15 -0
- data/lib/rdkafka/bindings/handle.rb +16 -0
- data/lib/rdkafka/bindings/messages.rb +28 -0
- data/lib/rdkafka/bindings/metadata.rb +14 -0
- data/lib/rdkafka/bindings/polling.rb +17 -0
- data/lib/rdkafka/bindings/producer.rb +77 -0
- data/lib/rdkafka/bindings/structs.rb +62 -0
- data/lib/rdkafka/bindings.rb +69 -294
- data/lib/rdkafka/callbacks/alter_consumer_group_offsets_handler.rb +65 -0
- data/lib/rdkafka/callbacks/base_handler.rb +62 -0
- data/lib/rdkafka/callbacks/create_acl_handler.rb +37 -0
- data/lib/rdkafka/callbacks/create_partitions_handler.rb +37 -0
- data/lib/rdkafka/callbacks/create_topic_handler.rb +37 -0
- data/lib/rdkafka/callbacks/delete_acl_handler.rb +42 -0
- data/lib/rdkafka/callbacks/delete_consumer_group_offsets_handler.rb +65 -0
- data/lib/rdkafka/callbacks/delete_groups_handler.rb +37 -0
- data/lib/rdkafka/callbacks/delete_records_handler.rb +38 -0
- data/lib/rdkafka/callbacks/delete_topic_handler.rb +37 -0
- data/lib/rdkafka/callbacks/describe_acl_handler.rb +35 -0
- data/lib/rdkafka/callbacks/describe_cluster_handler.rb +36 -0
- data/lib/rdkafka/callbacks/describe_configs_handler.rb +42 -0
- data/lib/rdkafka/callbacks/describe_consumer_groups_handler.rb +36 -0
- data/lib/rdkafka/callbacks/describe_topics_handler.rb +36 -0
- data/lib/rdkafka/callbacks/incremental_alter_configs_handler.rb +42 -0
- data/lib/rdkafka/callbacks/list_consumer_groups_handler.rb +39 -0
- data/lib/rdkafka/callbacks/list_offsets_handler.rb +42 -0
- data/lib/rdkafka/callbacks.rb +273 -52
- data/lib/rdkafka/clients.rb +81 -0
- data/lib/rdkafka/config.rb +333 -91
- data/lib/rdkafka/consumer/allocator.rb +38 -0
- data/lib/rdkafka/consumer/headers.rb +39 -25
- data/lib/rdkafka/consumer/message.rb +18 -20
- data/lib/rdkafka/consumer/partition.rb +15 -4
- data/lib/rdkafka/consumer/topic_partition_list.rb +82 -48
- data/lib/rdkafka/consumer.rb +765 -192
- data/lib/rdkafka/defaults.rb +123 -0
- data/lib/rdkafka/error.rb +40 -14
- data/lib/rdkafka/helpers/list_offsets.rb +127 -0
- data/lib/rdkafka/helpers/metadata.rb +29 -0
- data/lib/rdkafka/helpers/oauth.rb +95 -0
- data/lib/rdkafka/helpers/time.rb +19 -0
- data/lib/rdkafka/metadata.rb +138 -26
- data/lib/rdkafka/native_kafka.rb +142 -22
- data/lib/rdkafka/producer/delivery_handle.rb +27 -7
- data/lib/rdkafka/producer/delivery_report.rb +71 -4
- data/lib/rdkafka/producer/partitions_count_cache.rb +212 -0
- data/lib/rdkafka/producer.rb +422 -81
- data/lib/rdkafka/version.rb +6 -3
- data/lib/rdkafka.rb +73 -1
- data/package-lock.json +331 -0
- data/package.json +9 -0
- data/rdkafka.gemspec +78 -25
- data/renovate.json +111 -0
- metadata +114 -134
- data/.gitignore +0 -8
- data/.rspec +0 -1
- data/.semaphore/semaphore.yml +0 -27
- data/.yardopts +0 -2
- data/Gemfile +0 -5
- data/Guardfile +0 -19
- data/ext/README.md +0 -18
- data/spec/rdkafka/abstract_handle_spec.rb +0 -115
- data/spec/rdkafka/admin/create_topic_handle_spec.rb +0 -54
- data/spec/rdkafka/admin/create_topic_report_spec.rb +0 -18
- data/spec/rdkafka/admin/delete_topic_handle_spec.rb +0 -54
- data/spec/rdkafka/admin/delete_topic_report_spec.rb +0 -18
- data/spec/rdkafka/admin_spec.rb +0 -204
- data/spec/rdkafka/bindings_spec.rb +0 -136
- data/spec/rdkafka/callbacks_spec.rb +0 -22
- data/spec/rdkafka/config_spec.rb +0 -197
- data/spec/rdkafka/consumer/headers_spec.rb +0 -62
- data/spec/rdkafka/consumer/message_spec.rb +0 -141
- data/spec/rdkafka/consumer/partition_spec.rb +0 -59
- data/spec/rdkafka/consumer/topic_partition_list_spec.rb +0 -225
- data/spec/rdkafka/consumer_spec.rb +0 -1106
- data/spec/rdkafka/error_spec.rb +0 -91
- data/spec/rdkafka/metadata_spec.rb +0 -80
- data/spec/rdkafka/native_kafka_spec.rb +0 -124
- data/spec/rdkafka/producer/delivery_handle_spec.rb +0 -47
- data/spec/rdkafka/producer/delivery_report_spec.rb +0 -23
- data/spec/rdkafka/producer_spec.rb +0 -557
- data/spec/spec_helper.rb +0 -155
|
@@ -1,27 +1,64 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "ffi"
|
|
4
|
-
|
|
5
3
|
module Rdkafka
|
|
4
|
+
# This class serves as an abstract base class to represent handles within the Rdkafka module.
|
|
5
|
+
# As a subclass of `FFI::Struct`, this class provides a blueprint for other specific handle
|
|
6
|
+
# classes to inherit from, ensuring they adhere to a particular structure and behavior.
|
|
7
|
+
#
|
|
8
|
+
# Subclasses must define their own layout, and the layout must start with:
|
|
9
|
+
#
|
|
10
|
+
# layout :pending, :bool,
|
|
11
|
+
# :response, :int
|
|
6
12
|
class AbstractHandle < FFI::Struct
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
# layout :pending, :bool,
|
|
10
|
-
# :response, :int
|
|
13
|
+
include Helpers::Time
|
|
11
14
|
|
|
15
|
+
# Registry for registering all the handles.
|
|
12
16
|
REGISTRY = {}
|
|
17
|
+
# Guards REGISTRY mutations. The registry is shared across producing/consuming threads and the
|
|
18
|
+
# background polling thread (which removes handles from FFI callbacks), so the Hash must not be
|
|
19
|
+
# mutated concurrently. This is effectively safe on MRI under the GVL but not on JRuby, where a
|
|
20
|
+
# lost write could leave a handle unregistered (never unlocked -> `wait` times out for a
|
|
21
|
+
# delivered message) or never removed (permanent leak).
|
|
22
|
+
REGISTRY_MUTEX = Mutex.new
|
|
23
|
+
# Default wait timeout is 31 years
|
|
24
|
+
MAX_WAIT_TIMEOUT_FOREVER = 10_000_000_000
|
|
13
25
|
|
|
14
|
-
|
|
26
|
+
private_constant :REGISTRY_MUTEX
|
|
27
|
+
private_constant :MAX_WAIT_TIMEOUT_FOREVER
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
class << self
|
|
30
|
+
# Adds handle to the register
|
|
31
|
+
#
|
|
32
|
+
# @param handle [AbstractHandle] any handle we want to register
|
|
33
|
+
def register(handle)
|
|
34
|
+
address = handle.to_ptr.address
|
|
35
|
+
REGISTRY_MUTEX.synchronize { REGISTRY[address] = handle }
|
|
36
|
+
end
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
# Removes handle from the register based on the handle address
|
|
39
|
+
#
|
|
40
|
+
# @param address [Integer] address of the registered handle we want to remove
|
|
41
|
+
def remove(address)
|
|
42
|
+
REGISTRY_MUTEX.synchronize { REGISTRY.delete(address) }
|
|
43
|
+
end
|
|
21
44
|
end
|
|
22
45
|
|
|
23
|
-
|
|
24
|
-
|
|
46
|
+
# Operation result prepared by the background event callback. Background events are
|
|
47
|
+
# destroyed as soon as the callback returns, so anything the waiting thread needs has to be
|
|
48
|
+
# copied out of event-owned memory into Ruby objects and stored here before `#unlock` runs.
|
|
49
|
+
# When result parsing fails, holds the captured exception so it can be re-raised on the
|
|
50
|
+
# waiting thread.
|
|
51
|
+
attr_accessor :result
|
|
52
|
+
|
|
53
|
+
# Broker-provided error message copied out of event-owned memory by the background event
|
|
54
|
+
# callback, used by `#raise_error`.
|
|
55
|
+
attr_accessor :broker_message
|
|
56
|
+
|
|
57
|
+
def initialize
|
|
58
|
+
@mutex = Thread::Mutex.new
|
|
59
|
+
@resource = Thread::ConditionVariable.new
|
|
60
|
+
|
|
61
|
+
super
|
|
25
62
|
end
|
|
26
63
|
|
|
27
64
|
# Whether the handle is still pending.
|
|
@@ -32,36 +69,67 @@ module Rdkafka
|
|
|
32
69
|
end
|
|
33
70
|
|
|
34
71
|
# Wait for the operation to complete or raise an error if this takes longer than the timeout.
|
|
35
|
-
# If there is a timeout this does not mean the operation failed, rdkafka might still be working
|
|
36
|
-
# In this case it is possible to call wait again.
|
|
72
|
+
# If there is a timeout this does not mean the operation failed, rdkafka might still be working
|
|
73
|
+
# on the operation. In this case it is possible to call wait again.
|
|
74
|
+
#
|
|
75
|
+
# @param max_wait_timeout [Numeric, nil] DEPRECATED: Use max_wait_timeout_ms instead.
|
|
76
|
+
# Amount of time in seconds to wait before timing out. Will be removed in v1.0.0.
|
|
77
|
+
# @param max_wait_timeout_ms [Numeric, nil] Amount of time in milliseconds to wait before
|
|
78
|
+
# timing out. If this is nil we will wait forever. Defaults to 60,000ms (60 seconds).
|
|
79
|
+
# @param raise_response_error [Boolean] should we raise error when waiting finishes
|
|
37
80
|
#
|
|
38
|
-
# @
|
|
39
|
-
# @param wait_timeout [Numeric] Amount of time we should wait before we recheck if the operation has completed
|
|
81
|
+
# @return [Object] Operation-specific result
|
|
40
82
|
#
|
|
41
83
|
# @raise [RdkafkaError] When the operation failed
|
|
42
84
|
# @raise [WaitTimeoutError] When the timeout has been reached and the handle is still pending
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
def wait(max_wait_timeout: :not_provided, max_wait_timeout_ms: :not_provided, raise_response_error: true)
|
|
86
|
+
# Determine which timeout value to use
|
|
87
|
+
if max_wait_timeout != :not_provided && max_wait_timeout_ms != :not_provided
|
|
88
|
+
warn "DEPRECATION WARNING: Both max_wait_timeout and max_wait_timeout_ms were provided. " \
|
|
89
|
+
"Using max_wait_timeout_ms. The max_wait_timeout parameter is deprecated and will be removed in v1.0.0."
|
|
90
|
+
timeout_ms = max_wait_timeout_ms
|
|
91
|
+
elsif max_wait_timeout != :not_provided
|
|
92
|
+
warn "DEPRECATION WARNING: max_wait_timeout (seconds) is deprecated. " \
|
|
93
|
+
"Use max_wait_timeout_ms (milliseconds) instead. This parameter will be removed in v1.0.0."
|
|
94
|
+
timeout_ms = max_wait_timeout ? (max_wait_timeout * 1000).to_i : nil
|
|
95
|
+
elsif max_wait_timeout_ms == :not_provided
|
|
96
|
+
timeout_ms = Defaults::HANDLE_WAIT_TIMEOUT_MS
|
|
97
|
+
else
|
|
98
|
+
timeout_ms = max_wait_timeout_ms
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
timeout_s = timeout_ms ? timeout_ms / 1000.0 : nil
|
|
102
|
+
timeout = timeout_s ? monotonic_now + timeout_s : MAX_WAIT_TIMEOUT_FOREVER
|
|
103
|
+
|
|
104
|
+
@mutex.synchronize do
|
|
105
|
+
loop do
|
|
106
|
+
if pending?
|
|
107
|
+
to_wait = (timeout - monotonic_now)
|
|
108
|
+
|
|
109
|
+
if to_wait.positive?
|
|
110
|
+
@resource.wait(@mutex, to_wait)
|
|
111
|
+
else
|
|
112
|
+
raise WaitTimeoutError.new(
|
|
113
|
+
"Waiting for #{operation_name} timed out after #{timeout_ms} ms"
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
elsif self[:response] != 0 && raise_response_error
|
|
117
|
+
raise_error
|
|
118
|
+
else
|
|
119
|
+
return create_result
|
|
55
120
|
end
|
|
56
|
-
sleep wait_timeout
|
|
57
|
-
elsif self[:response] != 0
|
|
58
|
-
raise_error
|
|
59
|
-
else
|
|
60
|
-
return create_result
|
|
61
121
|
end
|
|
62
122
|
end
|
|
63
123
|
end
|
|
64
124
|
|
|
125
|
+
# Unlock the resources
|
|
126
|
+
def unlock
|
|
127
|
+
@mutex.synchronize do
|
|
128
|
+
self[:pending] = false
|
|
129
|
+
@resource.broadcast
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
65
133
|
# @return [String] the name of the operation (e.g. "delivery")
|
|
66
134
|
def operation_name
|
|
67
135
|
raise "Must be implemented by subclass!"
|
|
@@ -72,6 +140,17 @@ module Rdkafka
|
|
|
72
140
|
raise "Must be implemented by subclass!"
|
|
73
141
|
end
|
|
74
142
|
|
|
143
|
+
# Returns the operation result prepared by the background event callback, re-raising an
|
|
144
|
+
# exception that was captured while the event memory was still readable.
|
|
145
|
+
#
|
|
146
|
+
# @return [Object] operation-specific result
|
|
147
|
+
# @raise [RdkafkaError] when result parsing in the event callback failed
|
|
148
|
+
def prepared_result
|
|
149
|
+
raise(result) if result.is_a?(Exception)
|
|
150
|
+
|
|
151
|
+
result
|
|
152
|
+
end
|
|
153
|
+
|
|
75
154
|
# Allow subclasses to override
|
|
76
155
|
def raise_error
|
|
77
156
|
raise RdkafkaError.new(self[:response])
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Extracts attributes of rd_kafka_AclBinding_t
|
|
6
|
+
class AclBindingResult
|
|
7
|
+
attr_reader :result_error, :error_string, :matching_acl_resource_type,
|
|
8
|
+
:matching_acl_resource_name, :matching_acl_resource_pattern_type,
|
|
9
|
+
:matching_acl_principal, :matching_acl_host, :matching_acl_operation,
|
|
10
|
+
:matching_acl_permission_type
|
|
11
|
+
|
|
12
|
+
# This attribute was initially released under the name that is now an alias
|
|
13
|
+
# We keep it for backwards compatibility but it was changed for the consistency
|
|
14
|
+
alias_method :matching_acl_pattern_type, :matching_acl_resource_pattern_type
|
|
15
|
+
|
|
16
|
+
# @param matching_acl [FFI::Pointer] pointer to the ACL binding struct
|
|
17
|
+
def initialize(matching_acl)
|
|
18
|
+
rd_kafka_error_pointer = Rdkafka::Bindings.rd_kafka_AclBinding_error(matching_acl)
|
|
19
|
+
@result_error = Rdkafka::Bindings.rd_kafka_error_code(rd_kafka_error_pointer)
|
|
20
|
+
error_string = Rdkafka::Bindings.rd_kafka_error_string(rd_kafka_error_pointer)
|
|
21
|
+
|
|
22
|
+
if error_string != FFI::Pointer::NULL
|
|
23
|
+
@error_string = error_string.read_string
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@matching_acl_resource_type = Rdkafka::Bindings.rd_kafka_AclBinding_restype(matching_acl)
|
|
27
|
+
matching_acl_resource_name = Rdkafka::Bindings.rd_kafka_AclBinding_name(matching_acl)
|
|
28
|
+
|
|
29
|
+
if matching_acl_resource_name != FFI::Pointer::NULL
|
|
30
|
+
@matching_acl_resource_name = matching_acl_resource_name.read_string
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
@matching_acl_resource_pattern_type = Rdkafka::Bindings.rd_kafka_AclBinding_resource_pattern_type(matching_acl)
|
|
34
|
+
matching_acl_principal = Rdkafka::Bindings.rd_kafka_AclBinding_principal(matching_acl)
|
|
35
|
+
|
|
36
|
+
if matching_acl_principal != FFI::Pointer::NULL
|
|
37
|
+
@matching_acl_principal = matching_acl_principal.read_string
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
matching_acl_host = Rdkafka::Bindings.rd_kafka_AclBinding_host(matching_acl)
|
|
41
|
+
|
|
42
|
+
if matching_acl_host != FFI::Pointer::NULL
|
|
43
|
+
@matching_acl_host = matching_acl_host.read_string
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
@matching_acl_operation = Rdkafka::Bindings.rd_kafka_AclBinding_operation(matching_acl)
|
|
47
|
+
@matching_acl_permission_type = Rdkafka::Bindings.rd_kafka_AclBinding_permission_type(matching_acl)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for alter consumer group offsets operation
|
|
6
|
+
class AlterConsumerGroupOffsetsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"alter consumer group offsets"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Creates the result report
|
|
16
|
+
# @return [AlterConsumerGroupOffsetsReport]
|
|
17
|
+
def create_result
|
|
18
|
+
prepared_result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Raises an error if the operation failed
|
|
22
|
+
# @raise [RdkafkaError]
|
|
23
|
+
def raise_error
|
|
24
|
+
raise RdkafkaError.new(
|
|
25
|
+
self[:response],
|
|
26
|
+
broker_message: broker_message
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for alter consumer group offsets operation result
|
|
6
|
+
class AlterConsumerGroupOffsetsReport
|
|
7
|
+
# @return [String, nil] the group the operation ran against
|
|
8
|
+
attr_reader :group_name
|
|
9
|
+
|
|
10
|
+
# @return [String, nil] group level error message, if any
|
|
11
|
+
attr_reader :error_string
|
|
12
|
+
|
|
13
|
+
# Per partition outcomes, each with `:topic`, `:partition`, `:offset` and `:error`
|
|
14
|
+
# (an `RdkafkaError` or nil). Partitions are reported individually because Kafka can
|
|
15
|
+
# fail some and accept others within a single request.
|
|
16
|
+
# @return [Array<Hash>]
|
|
17
|
+
attr_reader :partitions
|
|
18
|
+
|
|
19
|
+
# @param error_string [FFI::Pointer] pointer to the group level error string
|
|
20
|
+
# @param result_name [FFI::Pointer] pointer to the group name
|
|
21
|
+
# @param partitions_ptr [FFI::Pointer] pointer to the per partition result list
|
|
22
|
+
def initialize(error_string, result_name, partitions_ptr = FFI::Pointer::NULL)
|
|
23
|
+
@error_string = error_string.read_string if error_string != FFI::Pointer::NULL
|
|
24
|
+
@group_name = result_name.read_string if result_name != FFI::Pointer::NULL
|
|
25
|
+
@partitions = extract_partitions(partitions_ptr)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# @param partitions_ptr [FFI::Pointer] pointer to a native topic partition list
|
|
31
|
+
# @return [Array<Hash>]
|
|
32
|
+
def extract_partitions(partitions_ptr)
|
|
33
|
+
return [] if partitions_ptr.nil? || partitions_ptr.null?
|
|
34
|
+
|
|
35
|
+
native = Bindings::TopicPartitionList.new(partitions_ptr)
|
|
36
|
+
|
|
37
|
+
Array.new(native[:cnt]) do |i|
|
|
38
|
+
tp = Bindings::TopicPartition.new(native[:elems] + (i * Bindings::TopicPartition.size))
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
topic: tp[:topic],
|
|
42
|
+
partition: tp[:partition],
|
|
43
|
+
offset: tp[:offset],
|
|
44
|
+
error: tp[:err].zero? ? nil : RdkafkaError.new(tp[:err])
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# A single config binding result that represents its values extracted from C
|
|
6
|
+
class ConfigBindingResult
|
|
7
|
+
attr_reader :name, :value, :read_only, :default, :sensitive, :synonym, :synonyms
|
|
8
|
+
|
|
9
|
+
# @param config_ptr [FFI::Pointer] config pointer
|
|
10
|
+
def initialize(config_ptr)
|
|
11
|
+
@name = Bindings.rd_kafka_ConfigEntry_name(config_ptr)
|
|
12
|
+
@value = Bindings.rd_kafka_ConfigEntry_value(config_ptr)
|
|
13
|
+
@read_only = Bindings.rd_kafka_ConfigEntry_is_read_only(config_ptr)
|
|
14
|
+
@default = Bindings.rd_kafka_ConfigEntry_is_default(config_ptr)
|
|
15
|
+
@sensitive = Bindings.rd_kafka_ConfigEntry_is_sensitive(config_ptr)
|
|
16
|
+
@synonym = Bindings.rd_kafka_ConfigEntry_is_synonym(config_ptr)
|
|
17
|
+
@synonyms = []
|
|
18
|
+
|
|
19
|
+
# The code below builds up the config synonyms using same config binding
|
|
20
|
+
pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
|
|
21
|
+
synonym_ptr = Bindings.rd_kafka_ConfigEntry_synonyms(config_ptr, pointer_to_size_t)
|
|
22
|
+
synonyms_ptr = synonym_ptr.read_array_of_pointer(pointer_to_size_t.read_int)
|
|
23
|
+
|
|
24
|
+
(1..pointer_to_size_t.read_int).map do |ar|
|
|
25
|
+
@synonyms << self.class.new(synonyms_ptr[ar - 1])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# A simple binding that represents the requested config resource
|
|
6
|
+
class ConfigResourceBindingResult
|
|
7
|
+
attr_reader :name, :type, :configs, :configs_count
|
|
8
|
+
|
|
9
|
+
# @param config_resource_ptr [FFI::Pointer] pointer to the config resource struct
|
|
10
|
+
def initialize(config_resource_ptr)
|
|
11
|
+
ffi_binding = Bindings::ConfigResource.new(config_resource_ptr)
|
|
12
|
+
|
|
13
|
+
@name = ffi_binding[:name]
|
|
14
|
+
@type = ffi_binding[:type]
|
|
15
|
+
@configs = []
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for create ACL operation
|
|
6
|
+
class CreateAclHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"create acl"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [CreateAclReport] report prepared by the background event callback, with
|
|
16
|
+
# rdkafka_response value as 0 and rdkafka_response_string value as empty string if the
|
|
17
|
+
# acl creation was successful
|
|
18
|
+
def create_result
|
|
19
|
+
prepared_result
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Raises an error if the operation failed
|
|
23
|
+
# @raise [RdkafkaError]
|
|
24
|
+
def raise_error
|
|
25
|
+
raise RdkafkaError.new(
|
|
26
|
+
self[:response],
|
|
27
|
+
broker_message: broker_message
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for create ACL operation result
|
|
6
|
+
class CreateAclReport
|
|
7
|
+
# Upon successful creation of Acl RD_KAFKA_RESP_ERR_NO_ERROR - 0 is returned as
|
|
8
|
+
# rdkafka_response
|
|
9
|
+
# @return [Integer]
|
|
10
|
+
attr_reader :rdkafka_response
|
|
11
|
+
|
|
12
|
+
# Upon successful creation of Acl empty string will be returned as rdkafka_response_string
|
|
13
|
+
# @return [String]
|
|
14
|
+
attr_reader :rdkafka_response_string
|
|
15
|
+
|
|
16
|
+
# @param rdkafka_response [Integer] response code from librdkafka
|
|
17
|
+
# @param rdkafka_response_string [FFI::Pointer] pointer to response string
|
|
18
|
+
def initialize(rdkafka_response:, rdkafka_response_string:)
|
|
19
|
+
@rdkafka_response = rdkafka_response
|
|
20
|
+
if rdkafka_response_string != FFI::Pointer::NULL
|
|
21
|
+
@rdkafka_response_string = rdkafka_response_string.read_string
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Rdkafka
|
|
2
|
+
class Admin
|
|
3
|
+
# Handle for create partitions operation
|
|
4
|
+
class CreatePartitionsHandle < AbstractHandle
|
|
5
|
+
layout :pending, :bool,
|
|
6
|
+
:response, :int
|
|
7
|
+
|
|
8
|
+
# @return [String] the name of the operation
|
|
9
|
+
def operation_name
|
|
10
|
+
"create partitions"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [CreatePartitionsReport] report prepared by the background event callback
|
|
14
|
+
def create_result
|
|
15
|
+
prepared_result
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Raises an error if the operation failed
|
|
19
|
+
# @raise [RdkafkaError]
|
|
20
|
+
def raise_error
|
|
21
|
+
raise RdkafkaError.new(
|
|
22
|
+
self[:response],
|
|
23
|
+
broker_message: broker_message
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
module Rdkafka
|
|
4
4
|
class Admin
|
|
5
|
+
# Handle for create topic operation
|
|
5
6
|
class CreateTopicHandle < AbstractHandle
|
|
6
7
|
layout :pending, :bool,
|
|
7
|
-
|
|
8
|
-
:error_string, :pointer,
|
|
9
|
-
:result_name, :pointer
|
|
8
|
+
:response, :int
|
|
10
9
|
|
|
11
10
|
# @return [String] the name of the operation
|
|
12
11
|
def operation_name
|
|
13
12
|
"create topic"
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
# @return [
|
|
15
|
+
# @return [CreateTopicReport] report prepared by the background event callback
|
|
17
16
|
def create_result
|
|
18
|
-
|
|
17
|
+
prepared_result
|
|
19
18
|
end
|
|
20
19
|
|
|
20
|
+
# Raises an error if the operation failed
|
|
21
|
+
# @raise [RdkafkaError]
|
|
21
22
|
def raise_error
|
|
22
23
|
raise RdkafkaError.new(
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
self[:response],
|
|
25
|
+
broker_message: broker_message
|
|
25
26
|
)
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Rdkafka
|
|
4
4
|
class Admin
|
|
5
|
+
# Report for create topic operation result
|
|
5
6
|
class CreateTopicReport
|
|
6
7
|
# Any error message generated from the CreateTopic
|
|
7
8
|
# @return [String]
|
|
@@ -11,12 +12,14 @@ module Rdkafka
|
|
|
11
12
|
# @return [String]
|
|
12
13
|
attr_reader :result_name
|
|
13
14
|
|
|
15
|
+
# @param error_string [FFI::Pointer] pointer to error string
|
|
16
|
+
# @param result_name [FFI::Pointer] pointer to topic name
|
|
14
17
|
def initialize(error_string, result_name)
|
|
15
18
|
if error_string != FFI::Pointer::NULL
|
|
16
19
|
@error_string = error_string.read_string
|
|
17
20
|
end
|
|
18
21
|
if result_name != FFI::Pointer::NULL
|
|
19
|
-
@result_name =
|
|
22
|
+
@result_name = result_name.read_string
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for delete ACL operation
|
|
6
|
+
class DeleteAclHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"delete acl"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [DeleteAclReport] report prepared by the background event callback, with an
|
|
16
|
+
# array of matching_acls
|
|
17
|
+
def create_result
|
|
18
|
+
prepared_result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Raises an error if the operation failed
|
|
22
|
+
# @raise [RdkafkaError]
|
|
23
|
+
def raise_error
|
|
24
|
+
raise RdkafkaError.new(
|
|
25
|
+
self[:response],
|
|
26
|
+
broker_message: broker_message
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for delete ACL operation result
|
|
6
|
+
class DeleteAclReport
|
|
7
|
+
# deleted acls
|
|
8
|
+
# @return [Rdkafka::Bindings::AclBindingResult]
|
|
9
|
+
attr_reader :deleted_acls
|
|
10
|
+
|
|
11
|
+
# @param matching_acls [FFI::Pointer] pointer to matching ACLs array
|
|
12
|
+
# @param matching_acls_count [Integer] number of matching ACLs
|
|
13
|
+
def initialize(matching_acls:, matching_acls_count:)
|
|
14
|
+
@deleted_acls = []
|
|
15
|
+
if matching_acls != FFI::Pointer::NULL
|
|
16
|
+
acl_binding_result_pointers = matching_acls.read_array_of_pointer(matching_acls_count)
|
|
17
|
+
(1..matching_acls_count).map do |matching_acl_index|
|
|
18
|
+
acl_binding_result = AclBindingResult.new(acl_binding_result_pointers[matching_acl_index - 1])
|
|
19
|
+
@deleted_acls << acl_binding_result
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for delete consumer group offsets operation
|
|
6
|
+
class DeleteConsumerGroupOffsetsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"delete consumer group offsets"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Creates the result report
|
|
16
|
+
# @return [DeleteConsumerGroupOffsetsReport]
|
|
17
|
+
def create_result
|
|
18
|
+
prepared_result
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Raises an error if the operation failed
|
|
22
|
+
# @raise [RdkafkaError]
|
|
23
|
+
def raise_error
|
|
24
|
+
raise RdkafkaError.new(
|
|
25
|
+
self[:response],
|
|
26
|
+
broker_message: broker_message
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for delete consumer group offsets operation result
|
|
6
|
+
class DeleteConsumerGroupOffsetsReport
|
|
7
|
+
# @return [String, nil] the group the operation ran against
|
|
8
|
+
attr_reader :group_name
|
|
9
|
+
|
|
10
|
+
# @return [String, nil] group level error message, if any
|
|
11
|
+
attr_reader :error_string
|
|
12
|
+
|
|
13
|
+
# Per partition outcomes, each with `:topic`, `:partition`, `:offset` and `:error`
|
|
14
|
+
# (an `RdkafkaError` or nil). Partitions are reported individually because Kafka can
|
|
15
|
+
# fail some and accept others within a single request.
|
|
16
|
+
# @return [Array<Hash>]
|
|
17
|
+
attr_reader :partitions
|
|
18
|
+
|
|
19
|
+
# @param error_string [FFI::Pointer] pointer to the group level error string
|
|
20
|
+
# @param result_name [FFI::Pointer] pointer to the group name
|
|
21
|
+
# @param partitions_ptr [FFI::Pointer] pointer to the per partition result list
|
|
22
|
+
def initialize(error_string, result_name, partitions_ptr = FFI::Pointer::NULL)
|
|
23
|
+
@error_string = error_string.read_string if error_string != FFI::Pointer::NULL
|
|
24
|
+
@group_name = result_name.read_string if result_name != FFI::Pointer::NULL
|
|
25
|
+
@partitions = extract_partitions(partitions_ptr)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# @param partitions_ptr [FFI::Pointer] pointer to a native topic partition list
|
|
31
|
+
# @return [Array<Hash>]
|
|
32
|
+
def extract_partitions(partitions_ptr)
|
|
33
|
+
return [] if partitions_ptr.nil? || partitions_ptr.null?
|
|
34
|
+
|
|
35
|
+
native = Bindings::TopicPartitionList.new(partitions_ptr)
|
|
36
|
+
|
|
37
|
+
Array.new(native[:cnt]) do |i|
|
|
38
|
+
tp = Bindings::TopicPartition.new(native[:elems] + (i * Bindings::TopicPartition.size))
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
topic: tp[:topic],
|
|
42
|
+
partition: tp[:partition],
|
|
43
|
+
offset: tp[:offset],
|
|
44
|
+
error: tp[:err].zero? ? nil : RdkafkaError.new(tp[:err])
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|