rdkafka 0.24.2 → 0.25.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 +10 -0
- data/Gemfile +9 -0
- data/README.md +2 -1
- data/dist/{librdkafka-2.11.1.tar.gz → librdkafka-2.12.1.tar.gz} +0 -0
- data/docker-compose-ssl.yml +1 -1
- data/docker-compose.yml +1 -1
- data/lib/rdkafka/abstract_handle.rb +23 -5
- data/lib/rdkafka/admin/acl_binding_result.rb +1 -1
- data/lib/rdkafka/admin/config_resource_binding_result.rb +1 -0
- data/lib/rdkafka/admin/create_acl_handle.rb +3 -0
- data/lib/rdkafka/admin/create_acl_report.rb +3 -0
- data/lib/rdkafka/admin/create_partitions_handle.rb +3 -0
- data/lib/rdkafka/admin/create_partitions_report.rb +1 -0
- data/lib/rdkafka/admin/create_topic_handle.rb +3 -0
- data/lib/rdkafka/admin/create_topic_report.rb +3 -0
- data/lib/rdkafka/admin/delete_acl_handle.rb +3 -0
- data/lib/rdkafka/admin/delete_acl_report.rb +3 -0
- data/lib/rdkafka/admin/delete_groups_handle.rb +5 -0
- data/lib/rdkafka/admin/delete_groups_report.rb +3 -0
- data/lib/rdkafka/admin/delete_topic_handle.rb +3 -0
- data/lib/rdkafka/admin/delete_topic_report.rb +3 -0
- data/lib/rdkafka/admin/describe_acl_handle.rb +3 -0
- data/lib/rdkafka/admin/describe_acl_report.rb +3 -0
- data/lib/rdkafka/admin/describe_configs_handle.rb +3 -0
- data/lib/rdkafka/admin/describe_configs_report.rb +6 -0
- data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +3 -0
- data/lib/rdkafka/admin/incremental_alter_configs_report.rb +6 -0
- data/lib/rdkafka/admin.rb +108 -112
- data/lib/rdkafka/bindings.rb +62 -29
- data/lib/rdkafka/callbacks.rb +71 -11
- data/lib/rdkafka/config.rb +20 -8
- data/lib/rdkafka/consumer/headers.rb +3 -2
- data/lib/rdkafka/consumer/message.rb +7 -3
- data/lib/rdkafka/consumer/partition.rb +6 -2
- data/lib/rdkafka/consumer/topic_partition_list.rb +8 -8
- data/lib/rdkafka/consumer.rb +40 -28
- data/lib/rdkafka/defaults.rb +106 -0
- data/lib/rdkafka/error.rb +16 -1
- data/lib/rdkafka/helpers/oauth.rb +11 -5
- data/lib/rdkafka/metadata.rb +29 -5
- data/lib/rdkafka/native_kafka.rb +26 -2
- data/lib/rdkafka/producer/delivery_report.rb +6 -2
- data/lib/rdkafka/producer/partitions_count_cache.rb +24 -14
- data/lib/rdkafka/producer.rb +49 -23
- data/lib/rdkafka/version.rb +6 -3
- data/lib/rdkafka.rb +1 -0
- data/rdkafka.gemspec +0 -7
- data/renovate.json +1 -8
- metadata +4 -87
data/lib/rdkafka/admin.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Rdkafka
|
|
4
|
+
# Admin client for Kafka administrative operations
|
|
4
5
|
class Admin
|
|
5
6
|
include Helpers::OAuth
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ module Rdkafka
|
|
|
8
9
|
# Allows us to retrieve librdkafka errors with descriptions
|
|
9
10
|
# Useful for debugging and building UIs, etc.
|
|
10
11
|
#
|
|
11
|
-
# @return [Hash
|
|
12
|
+
# @return [Hash{Integer => Hash}] hash with errors mapped by code
|
|
12
13
|
def describe_errors
|
|
13
14
|
# Memory pointers for the array of structures and count
|
|
14
15
|
p_error_descs = FFI::MemoryPointer.new(:pointer)
|
|
@@ -49,6 +50,7 @@ module Rdkafka
|
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
# @private
|
|
53
|
+
# @param native_kafka [NativeKafka] wrapper around the native Kafka handle
|
|
52
54
|
def initialize(native_kafka)
|
|
53
55
|
@native_kafka = native_kafka
|
|
54
56
|
|
|
@@ -69,6 +71,8 @@ module Rdkafka
|
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
|
|
74
|
+
# @return [Proc] finalizer proc for closing the admin
|
|
75
|
+
# @private
|
|
72
76
|
def finalizer
|
|
73
77
|
->(_) { close }
|
|
74
78
|
end
|
|
@@ -78,7 +82,7 @@ module Rdkafka
|
|
|
78
82
|
# @param topic_name [String, nil] metadat about particular topic or all if nil
|
|
79
83
|
# @param timeout_ms [Integer] metadata request timeout
|
|
80
84
|
# @return [Metadata] requested metadata
|
|
81
|
-
def metadata(topic_name = nil, timeout_ms =
|
|
85
|
+
def metadata(topic_name = nil, timeout_ms = Defaults::METADATA_TIMEOUT_MS)
|
|
82
86
|
closed_admin_check(__method__)
|
|
83
87
|
|
|
84
88
|
@native_kafka.with_inner do |inner|
|
|
@@ -100,9 +104,12 @@ module Rdkafka
|
|
|
100
104
|
|
|
101
105
|
# Create a topic with the given partition count and replication factor
|
|
102
106
|
#
|
|
107
|
+
# @param topic_name [String] name of the topic to create
|
|
108
|
+
# @param partition_count [Integer] number of partitions for the topic
|
|
109
|
+
# @param replication_factor [Integer] replication factor for the topic
|
|
110
|
+
# @param topic_config [Hash] optional topic configuration settings
|
|
103
111
|
# @return [CreateTopicHandle] Create topic handle that can be used to wait for the result of
|
|
104
112
|
# creating the topic
|
|
105
|
-
#
|
|
106
113
|
# @raise [ConfigError] When the partition count or replication factor are out of valid range
|
|
107
114
|
# @raise [RdkafkaError] When the topic name is invalid or the topic already exists
|
|
108
115
|
# @raise [RdkafkaError] When the topic configuration is invalid
|
|
@@ -149,7 +156,7 @@ module Rdkafka
|
|
|
149
156
|
# Create and register the handle we will return to the caller
|
|
150
157
|
create_topic_handle = CreateTopicHandle.new
|
|
151
158
|
create_topic_handle[:pending] = true
|
|
152
|
-
create_topic_handle[:response] =
|
|
159
|
+
create_topic_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
153
160
|
CreateTopicHandle.register(create_topic_handle)
|
|
154
161
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
155
162
|
Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATETOPICS)
|
|
@@ -178,6 +185,11 @@ module Rdkafka
|
|
|
178
185
|
create_topic_handle
|
|
179
186
|
end
|
|
180
187
|
|
|
188
|
+
# Deletes a consumer group
|
|
189
|
+
#
|
|
190
|
+
# @param group_id [String] the group id to delete
|
|
191
|
+
# @return [DeleteGroupsHandle] delete groups handle that can be used to wait for the result
|
|
192
|
+
# @raise [RdkafkaError] When deleting the group fails
|
|
181
193
|
def delete_group(group_id)
|
|
182
194
|
closed_admin_check(__method__)
|
|
183
195
|
|
|
@@ -202,7 +214,7 @@ module Rdkafka
|
|
|
202
214
|
# Create and register the handle we will return to the caller
|
|
203
215
|
delete_groups_handle = DeleteGroupsHandle.new
|
|
204
216
|
delete_groups_handle[:pending] = true
|
|
205
|
-
delete_groups_handle[:response] =
|
|
217
|
+
delete_groups_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
206
218
|
DeleteGroupsHandle.register(delete_groups_handle)
|
|
207
219
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
208
220
|
Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETETOPICS)
|
|
@@ -233,6 +245,7 @@ module Rdkafka
|
|
|
233
245
|
|
|
234
246
|
# Deletes the named topic
|
|
235
247
|
#
|
|
248
|
+
# @param topic_name [String] name of the topic to delete
|
|
236
249
|
# @return [DeleteTopicHandle] Delete topic handle that can be used to wait for the result of
|
|
237
250
|
# deleting the topic
|
|
238
251
|
# @raise [RdkafkaError] When the topic name is invalid or the topic does not exist
|
|
@@ -259,7 +272,7 @@ module Rdkafka
|
|
|
259
272
|
# Create and register the handle we will return to the caller
|
|
260
273
|
delete_topic_handle = DeleteTopicHandle.new
|
|
261
274
|
delete_topic_handle[:pending] = true
|
|
262
|
-
delete_topic_handle[:response] =
|
|
275
|
+
delete_topic_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
263
276
|
DeleteTopicHandle.register(delete_topic_handle)
|
|
264
277
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
265
278
|
Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_DELETETOPICS)
|
|
@@ -290,14 +303,12 @@ module Rdkafka
|
|
|
290
303
|
|
|
291
304
|
# Creates extra partitions for a given topic
|
|
292
305
|
#
|
|
293
|
-
# @param topic_name [String]
|
|
306
|
+
# @param topic_name [String] name of the topic
|
|
294
307
|
# @param partition_count [Integer] how many partitions we want to end up with for given topic
|
|
295
|
-
#
|
|
308
|
+
# @return [CreatePartitionsHandle] Create partitions handle that can be used to wait for the result
|
|
296
309
|
# @raise [ConfigError] When the partition count or replication factor are out of valid range
|
|
297
310
|
# @raise [RdkafkaError] When the topic name is invalid or the topic already exists
|
|
298
311
|
# @raise [RdkafkaError] When the topic configuration is invalid
|
|
299
|
-
#
|
|
300
|
-
# @return [CreateTopicHandle] Create topic handle that can be used to wait for the result of creating the topic
|
|
301
312
|
def create_partitions(topic_name, partition_count)
|
|
302
313
|
closed_admin_check(__method__)
|
|
303
314
|
|
|
@@ -327,7 +338,7 @@ module Rdkafka
|
|
|
327
338
|
# Create and register the handle we will return to the caller
|
|
328
339
|
create_partitions_handle = CreatePartitionsHandle.new
|
|
329
340
|
create_partitions_handle[:pending] = true
|
|
330
|
-
create_partitions_handle[:response] =
|
|
341
|
+
create_partitions_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
331
342
|
CreatePartitionsHandle.register(create_partitions_handle)
|
|
332
343
|
admin_options_ptr = Rdkafka::Bindings.rd_kafka_AdminOptions_new(inner, Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATEPARTITIONS)
|
|
333
344
|
Rdkafka::Bindings.rd_kafka_AdminOptions_set_opaque(admin_options_ptr, create_partitions_handle.to_ptr)
|
|
@@ -354,40 +365,34 @@ module Rdkafka
|
|
|
354
365
|
end
|
|
355
366
|
|
|
356
367
|
# Create acl
|
|
357
|
-
# @param resource_type - values of type rd_kafka_ResourceType_t
|
|
358
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7307
|
|
359
|
-
# valid values are:
|
|
360
|
-
# RD_KAFKA_RESOURCE_TOPIC = 2
|
|
361
|
-
# RD_KAFKA_RESOURCE_GROUP = 3
|
|
362
|
-
# RD_KAFKA_RESOURCE_BROKER = 4
|
|
363
|
-
# @param resource_pattern_type - values of type rd_kafka_ResourcePatternType_t
|
|
364
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7320
|
|
365
|
-
# valid values are:
|
|
366
|
-
# RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
|
|
367
|
-
# RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
|
|
368
|
-
# RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
|
|
369
|
-
# @param operation - values of type rd_kafka_AclOperation_t
|
|
370
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8403
|
|
371
|
-
# valid values are:
|
|
372
|
-
# RD_KAFKA_ACL_OPERATION_ALL = 2
|
|
373
|
-
# RD_KAFKA_ACL_OPERATION_READ = 3
|
|
374
|
-
# RD_KAFKA_ACL_OPERATION_WRITE = 4
|
|
375
|
-
# RD_KAFKA_ACL_OPERATION_CREATE = 5
|
|
376
|
-
# RD_KAFKA_ACL_OPERATION_DELETE = 6
|
|
377
|
-
# RD_KAFKA_ACL_OPERATION_ALTER = 7
|
|
378
|
-
# RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
|
|
379
|
-
# RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
|
|
380
|
-
# RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
|
|
381
|
-
# RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
|
|
382
|
-
# RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
|
|
383
|
-
# @param permission_type - values of type rd_kafka_AclPermissionType_t
|
|
384
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
|
|
385
|
-
# valid values are:
|
|
386
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
387
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
388
368
|
#
|
|
369
|
+
# @param resource_type [Integer] rd_kafka_ResourceType_t value:
|
|
370
|
+
# - RD_KAFKA_RESOURCE_TOPIC = 2
|
|
371
|
+
# - RD_KAFKA_RESOURCE_GROUP = 3
|
|
372
|
+
# - RD_KAFKA_RESOURCE_BROKER = 4
|
|
373
|
+
# @param resource_name [String] name of the resource
|
|
374
|
+
# @param resource_pattern_type [Integer] rd_kafka_ResourcePatternType_t value:
|
|
375
|
+
# - RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
|
|
376
|
+
# - RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
|
|
377
|
+
# - RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
|
|
378
|
+
# @param principal [String] principal (e.g., "User:alice")
|
|
379
|
+
# @param host [String] host address
|
|
380
|
+
# @param operation [Integer] rd_kafka_AclOperation_t value:
|
|
381
|
+
# - RD_KAFKA_ACL_OPERATION_ALL = 2
|
|
382
|
+
# - RD_KAFKA_ACL_OPERATION_READ = 3
|
|
383
|
+
# - RD_KAFKA_ACL_OPERATION_WRITE = 4
|
|
384
|
+
# - RD_KAFKA_ACL_OPERATION_CREATE = 5
|
|
385
|
+
# - RD_KAFKA_ACL_OPERATION_DELETE = 6
|
|
386
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER = 7
|
|
387
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
|
|
388
|
+
# - RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
|
|
389
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
|
|
390
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
|
|
391
|
+
# - RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
|
|
392
|
+
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
393
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
394
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
389
395
|
# @return [CreateAclHandle] Create acl handle that can be used to wait for the result of creating the acl
|
|
390
|
-
#
|
|
391
396
|
# @raise [RdkafkaError]
|
|
392
397
|
def create_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
393
398
|
closed_admin_check(__method__)
|
|
@@ -427,7 +432,7 @@ module Rdkafka
|
|
|
427
432
|
# Create and register the handle that we will return to the caller
|
|
428
433
|
create_acl_handle = CreateAclHandle.new
|
|
429
434
|
create_acl_handle[:pending] = true
|
|
430
|
-
create_acl_handle[:response] =
|
|
435
|
+
create_acl_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
431
436
|
CreateAclHandle.register(create_acl_handle)
|
|
432
437
|
|
|
433
438
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
@@ -460,39 +465,33 @@ module Rdkafka
|
|
|
460
465
|
|
|
461
466
|
# Delete acl
|
|
462
467
|
#
|
|
463
|
-
# @param resource_type
|
|
464
|
-
#
|
|
465
|
-
#
|
|
466
|
-
#
|
|
467
|
-
#
|
|
468
|
-
#
|
|
469
|
-
#
|
|
470
|
-
#
|
|
471
|
-
#
|
|
472
|
-
#
|
|
473
|
-
#
|
|
474
|
-
#
|
|
475
|
-
#
|
|
476
|
-
#
|
|
477
|
-
#
|
|
478
|
-
#
|
|
479
|
-
#
|
|
480
|
-
#
|
|
481
|
-
#
|
|
482
|
-
#
|
|
483
|
-
#
|
|
484
|
-
#
|
|
485
|
-
#
|
|
486
|
-
#
|
|
487
|
-
#
|
|
488
|
-
#
|
|
489
|
-
# @param permission_type - values of type rd_kafka_AclPermissionType_t
|
|
490
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
|
|
491
|
-
# valid values are:
|
|
492
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
493
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
468
|
+
# @param resource_type [Integer] rd_kafka_ResourceType_t value:
|
|
469
|
+
# - RD_KAFKA_RESOURCE_TOPIC = 2
|
|
470
|
+
# - RD_KAFKA_RESOURCE_GROUP = 3
|
|
471
|
+
# - RD_KAFKA_RESOURCE_BROKER = 4
|
|
472
|
+
# @param resource_name [String, nil] name of the resource or nil for any
|
|
473
|
+
# @param resource_pattern_type [Integer] rd_kafka_ResourcePatternType_t value:
|
|
474
|
+
# - RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
|
|
475
|
+
# - RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
|
|
476
|
+
# - RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
|
|
477
|
+
# @param principal [String, nil] principal (e.g., "User:alice") or nil for any
|
|
478
|
+
# @param host [String, nil] host address or nil for any
|
|
479
|
+
# @param operation [Integer] rd_kafka_AclOperation_t value:
|
|
480
|
+
# - RD_KAFKA_ACL_OPERATION_ALL = 2
|
|
481
|
+
# - RD_KAFKA_ACL_OPERATION_READ = 3
|
|
482
|
+
# - RD_KAFKA_ACL_OPERATION_WRITE = 4
|
|
483
|
+
# - RD_KAFKA_ACL_OPERATION_CREATE = 5
|
|
484
|
+
# - RD_KAFKA_ACL_OPERATION_DELETE = 6
|
|
485
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER = 7
|
|
486
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
|
|
487
|
+
# - RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
|
|
488
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
|
|
489
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
|
|
490
|
+
# - RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
|
|
491
|
+
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
492
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
493
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
494
494
|
# @return [DeleteAclHandle] Delete acl handle that can be used to wait for the result of deleting the acl
|
|
495
|
-
#
|
|
496
495
|
# @raise [RdkafkaError]
|
|
497
496
|
def delete_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
498
497
|
closed_admin_check(__method__)
|
|
@@ -534,7 +533,7 @@ module Rdkafka
|
|
|
534
533
|
# Create and register the handle that we will return to the caller
|
|
535
534
|
delete_acl_handle = DeleteAclHandle.new
|
|
536
535
|
delete_acl_handle[:pending] = true
|
|
537
|
-
delete_acl_handle[:response] =
|
|
536
|
+
delete_acl_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
538
537
|
DeleteAclHandle.register(delete_acl_handle)
|
|
539
538
|
|
|
540
539
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
@@ -567,39 +566,33 @@ module Rdkafka
|
|
|
567
566
|
|
|
568
567
|
# Describe acls
|
|
569
568
|
#
|
|
570
|
-
# @param resource_type
|
|
571
|
-
#
|
|
572
|
-
#
|
|
573
|
-
#
|
|
574
|
-
#
|
|
575
|
-
#
|
|
576
|
-
#
|
|
577
|
-
#
|
|
578
|
-
#
|
|
579
|
-
#
|
|
580
|
-
#
|
|
581
|
-
#
|
|
582
|
-
#
|
|
583
|
-
#
|
|
584
|
-
#
|
|
585
|
-
#
|
|
586
|
-
#
|
|
587
|
-
#
|
|
588
|
-
#
|
|
589
|
-
#
|
|
590
|
-
#
|
|
591
|
-
#
|
|
592
|
-
#
|
|
593
|
-
#
|
|
594
|
-
#
|
|
595
|
-
#
|
|
596
|
-
# @param permission_type - values of type rd_kafka_AclPermissionType_t
|
|
597
|
-
# https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
|
|
598
|
-
# valid values are:
|
|
599
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
600
|
-
# RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
569
|
+
# @param resource_type [Integer] rd_kafka_ResourceType_t value:
|
|
570
|
+
# - RD_KAFKA_RESOURCE_TOPIC = 2
|
|
571
|
+
# - RD_KAFKA_RESOURCE_GROUP = 3
|
|
572
|
+
# - RD_KAFKA_RESOURCE_BROKER = 4
|
|
573
|
+
# @param resource_name [String, nil] name of the resource or nil for any
|
|
574
|
+
# @param resource_pattern_type [Integer] rd_kafka_ResourcePatternType_t value:
|
|
575
|
+
# - RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
|
|
576
|
+
# - RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
|
|
577
|
+
# - RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
|
|
578
|
+
# @param principal [String, nil] principal (e.g., "User:alice") or nil for any
|
|
579
|
+
# @param host [String, nil] host address or nil for any
|
|
580
|
+
# @param operation [Integer] rd_kafka_AclOperation_t value:
|
|
581
|
+
# - RD_KAFKA_ACL_OPERATION_ALL = 2
|
|
582
|
+
# - RD_KAFKA_ACL_OPERATION_READ = 3
|
|
583
|
+
# - RD_KAFKA_ACL_OPERATION_WRITE = 4
|
|
584
|
+
# - RD_KAFKA_ACL_OPERATION_CREATE = 5
|
|
585
|
+
# - RD_KAFKA_ACL_OPERATION_DELETE = 6
|
|
586
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER = 7
|
|
587
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
|
|
588
|
+
# - RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
|
|
589
|
+
# - RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
|
|
590
|
+
# - RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
|
|
591
|
+
# - RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
|
|
592
|
+
# @param permission_type [Integer] rd_kafka_AclPermissionType_t value:
|
|
593
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
594
|
+
# - RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
601
595
|
# @return [DescribeAclHandle] Describe acl handle that can be used to wait for the result of fetching acls
|
|
602
|
-
#
|
|
603
596
|
# @raise [RdkafkaError]
|
|
604
597
|
def describe_acl(resource_type:, resource_name:, resource_pattern_type:, principal:, host:, operation:, permission_type:)
|
|
605
598
|
closed_admin_check(__method__)
|
|
@@ -634,7 +627,7 @@ module Rdkafka
|
|
|
634
627
|
# Create and register the handle that we will return to the caller
|
|
635
628
|
describe_acl_handle = DescribeAclHandle.new
|
|
636
629
|
describe_acl_handle[:pending] = true
|
|
637
|
-
describe_acl_handle[:response] =
|
|
630
|
+
describe_acl_handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
638
631
|
DescribeAclHandle.register(describe_acl_handle)
|
|
639
632
|
|
|
640
633
|
admin_options_ptr = @native_kafka.with_inner do |inner|
|
|
@@ -680,7 +673,7 @@ module Rdkafka
|
|
|
680
673
|
|
|
681
674
|
handle = DescribeConfigsHandle.new
|
|
682
675
|
handle[:pending] = true
|
|
683
|
-
handle[:response] =
|
|
676
|
+
handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
684
677
|
|
|
685
678
|
queue_ptr = @native_kafka.with_inner do |inner|
|
|
686
679
|
Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
|
|
@@ -753,7 +746,7 @@ module Rdkafka
|
|
|
753
746
|
|
|
754
747
|
handle = IncrementalAlterConfigsHandle.new
|
|
755
748
|
handle[:pending] = true
|
|
756
|
-
handle[:response] =
|
|
749
|
+
handle[:response] = Rdkafka::Bindings::RD_KAFKA_PARTITION_UA
|
|
757
750
|
|
|
758
751
|
queue_ptr = @native_kafka.with_inner do |inner|
|
|
759
752
|
Rdkafka::Bindings.rd_kafka_queue_get_background(inner)
|
|
@@ -825,6 +818,9 @@ module Rdkafka
|
|
|
825
818
|
|
|
826
819
|
private
|
|
827
820
|
|
|
821
|
+
# Checks if the admin is closed and raises an error if so
|
|
822
|
+
# @param method [Symbol] name of the calling method for error context
|
|
823
|
+
# @raise [ClosedAdminError] when the admin is closed
|
|
828
824
|
def closed_admin_check(method)
|
|
829
825
|
raise Rdkafka::ClosedAdminError.new(method) if closed?
|
|
830
826
|
end
|
data/lib/rdkafka/bindings.rb
CHANGED
|
@@ -14,6 +14,8 @@ module Rdkafka
|
|
|
14
14
|
module Bindings
|
|
15
15
|
extend FFI::Library
|
|
16
16
|
|
|
17
|
+
# Returns the library extension based on the host OS
|
|
18
|
+
# @return [String] 'dylib' on macOS, 'so' on other systems
|
|
17
19
|
def self.lib_extension
|
|
18
20
|
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
|
19
21
|
'dylib'
|
|
@@ -22,7 +24,39 @@ module Rdkafka
|
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
ffi_lib
|
|
27
|
+
# Wrap ffi_lib to provide better error messages for glibc compatibility issues
|
|
28
|
+
begin
|
|
29
|
+
ffi_lib File.join(__dir__, "../../ext/librdkafka.#{lib_extension}")
|
|
30
|
+
rescue LoadError => e
|
|
31
|
+
error_message = e.message
|
|
32
|
+
|
|
33
|
+
# Check if this is a glibc version mismatch error
|
|
34
|
+
if error_message =~ /GLIBC_[\d.]+['"` ]?\s*not found/i
|
|
35
|
+
glibc_version = error_message[/GLIBC_([\d.]+)/, 1] || 'unknown'
|
|
36
|
+
|
|
37
|
+
raise Rdkafka::LibraryLoadError, <<~ERROR_MSG.strip
|
|
38
|
+
Failed to load librdkafka due to glibc compatibility issue.
|
|
39
|
+
|
|
40
|
+
The precompiled librdkafka binary requires glibc version #{glibc_version} or higher,
|
|
41
|
+
but your system has an older version installed.
|
|
42
|
+
|
|
43
|
+
To resolve this issue, you have two options:
|
|
44
|
+
|
|
45
|
+
1. Upgrade your system to a supported platform (recommended)
|
|
46
|
+
|
|
47
|
+
2. Force compilation from source by reinstalling without the precompiled binary:
|
|
48
|
+
gem install rdkafka --platform=ruby
|
|
49
|
+
|
|
50
|
+
Or if using Bundler, add to your Gemfile:
|
|
51
|
+
gem 'rdkafka', force_ruby_platform: true
|
|
52
|
+
|
|
53
|
+
Original error: #{error_message}
|
|
54
|
+
ERROR_MSG
|
|
55
|
+
else
|
|
56
|
+
# Re-raise the original error if it's not a glibc issue
|
|
57
|
+
raise
|
|
58
|
+
end
|
|
59
|
+
end
|
|
26
60
|
|
|
27
61
|
RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS = -175
|
|
28
62
|
RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS = -174
|
|
@@ -35,8 +69,12 @@ module Rdkafka
|
|
|
35
69
|
RD_KAFKA_OFFSET_STORED = -1000
|
|
36
70
|
RD_KAFKA_OFFSET_INVALID = -1001
|
|
37
71
|
|
|
72
|
+
RD_KAFKA_PARTITION_UA = -1
|
|
73
|
+
RD_KAFKA_PARTITION_UA_STR = RD_KAFKA_PARTITION_UA.to_s.freeze
|
|
74
|
+
|
|
38
75
|
EMPTY_HASH = {}.freeze
|
|
39
76
|
|
|
77
|
+
# FFI struct for size_t pointer wrapper
|
|
40
78
|
class SizePtr < FFI::Struct
|
|
41
79
|
layout :value, :size_t
|
|
42
80
|
end
|
|
@@ -60,8 +98,7 @@ module Rdkafka
|
|
|
60
98
|
attach_function :rd_kafka_metadata, [:pointer, :int, :pointer, :pointer, :int], :int, blocking: true
|
|
61
99
|
attach_function :rd_kafka_metadata_destroy, [:pointer], :void, blocking: true
|
|
62
100
|
|
|
63
|
-
#
|
|
64
|
-
|
|
101
|
+
# FFI struct representing a Kafka message (rd_kafka_message_t)
|
|
65
102
|
class Message < FFI::Struct
|
|
66
103
|
layout :err, :int,
|
|
67
104
|
:rkt, :pointer,
|
|
@@ -80,8 +117,7 @@ module Rdkafka
|
|
|
80
117
|
attach_function :rd_kafka_topic_destroy, [:pointer], :pointer
|
|
81
118
|
attach_function :rd_kafka_topic_name, [:pointer], :string
|
|
82
119
|
|
|
83
|
-
#
|
|
84
|
-
|
|
120
|
+
# FFI struct representing a topic partition (rd_kafka_topic_partition_t)
|
|
85
121
|
class TopicPartition < FFI::Struct
|
|
86
122
|
layout :topic, :string,
|
|
87
123
|
:partition, :int32,
|
|
@@ -93,6 +129,7 @@ module Rdkafka
|
|
|
93
129
|
:_private, :pointer
|
|
94
130
|
end
|
|
95
131
|
|
|
132
|
+
# FFI struct representing a topic partition list (rd_kafka_topic_partition_list_t)
|
|
96
133
|
class TopicPartitionList < FFI::Struct
|
|
97
134
|
layout :cnt, :int,
|
|
98
135
|
:size, :int,
|
|
@@ -105,12 +142,10 @@ module Rdkafka
|
|
|
105
142
|
attach_function :rd_kafka_topic_partition_list_destroy, [:pointer], :void
|
|
106
143
|
attach_function :rd_kafka_topic_partition_list_copy, [:pointer], :pointer
|
|
107
144
|
|
|
108
|
-
#
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
# details. Each resource will also have separate errors results if obtaining configuration
|
|
113
|
-
# was not possible for any reason
|
|
145
|
+
# FFI struct representing a config resource (rd_kafka_ConfigResource_t)
|
|
146
|
+
# Structs for management of configurations. Each configuration is attached to a resource
|
|
147
|
+
# and one resource can have many configuration details. Each resource will also have
|
|
148
|
+
# separate errors results if obtaining configuration was not possible for any reason
|
|
114
149
|
class ConfigResource < FFI::Struct
|
|
115
150
|
layout :type, :int,
|
|
116
151
|
:name, :string
|
|
@@ -147,7 +182,7 @@ module Rdkafka
|
|
|
147
182
|
RD_KAFKA_ALTER_CONFIG_OP_TYPE_APPEND = 2
|
|
148
183
|
RD_KAFKA_ALTER_CONFIG_OP_TYPE_SUBTRACT = 3
|
|
149
184
|
|
|
150
|
-
#
|
|
185
|
+
# FFI struct for error description (rd_kafka_err_desc)
|
|
151
186
|
class NativeErrorDesc < FFI::Struct
|
|
152
187
|
layout :code, :int,
|
|
153
188
|
:name, :pointer,
|
|
@@ -234,7 +269,7 @@ module Rdkafka
|
|
|
234
269
|
# Since this cache is shared, having few consumers and/or producers in one process will
|
|
235
270
|
# automatically improve the querying times even with low refresh times.
|
|
236
271
|
(stats['topics'] || EMPTY_HASH).each do |topic_name, details|
|
|
237
|
-
partitions_count = details['partitions'].keys.reject { |k| k ==
|
|
272
|
+
partitions_count = details['partitions'].keys.reject { |k| k == RD_KAFKA_PARTITION_UA_STR }.size
|
|
238
273
|
|
|
239
274
|
next unless partitions_count.positive?
|
|
240
275
|
|
|
@@ -245,7 +280,7 @@ module Rdkafka
|
|
|
245
280
|
end
|
|
246
281
|
|
|
247
282
|
# Return 0 so librdkafka frees the json string
|
|
248
|
-
|
|
283
|
+
RD_KAFKA_RESP_ERR_NO_ERROR
|
|
249
284
|
end
|
|
250
285
|
|
|
251
286
|
ErrorCallback = FFI::Function.new(
|
|
@@ -368,7 +403,6 @@ module Rdkafka
|
|
|
368
403
|
attach_function :rd_kafka_query_watermark_offsets, [:pointer, :string, :int, :pointer, :pointer, :int], :int
|
|
369
404
|
|
|
370
405
|
# Producer
|
|
371
|
-
|
|
372
406
|
RD_KAFKA_VTYPE_END = 0
|
|
373
407
|
RD_KAFKA_VTYPE_TOPIC = 1
|
|
374
408
|
RD_KAFKA_VTYPE_RKT = 2
|
|
@@ -390,16 +424,25 @@ module Rdkafka
|
|
|
390
424
|
callback :delivery_cb, [:pointer, :pointer, :pointer], :void
|
|
391
425
|
attach_function :rd_kafka_conf_set_dr_msg_cb, [:pointer, :delivery_cb], :void
|
|
392
426
|
|
|
393
|
-
#
|
|
427
|
+
# Hash mapping partitioner names to their FFI function symbols
|
|
428
|
+
# @return [Hash{String => Symbol}]
|
|
394
429
|
PARTITIONERS = %w(random consistent consistent_random murmur2 murmur2_random fnv1a fnv1a_random).each_with_object({}) do |name, hsh|
|
|
395
430
|
method_name = "rd_kafka_msg_partitioner_#{name}".to_sym
|
|
396
431
|
attach_function method_name, [:pointer, :pointer, :size_t, :int32, :pointer, :pointer], :int32
|
|
397
432
|
hsh[name] = method_name
|
|
398
433
|
end
|
|
399
434
|
|
|
435
|
+
# Calculates the partition for a message based on the partitioner
|
|
436
|
+
#
|
|
437
|
+
# @param topic_ptr [FFI::Pointer] pointer to the topic handle
|
|
438
|
+
# @param str [String] the partition key string
|
|
439
|
+
# @param partition_count [Integer, nil] number of partitions
|
|
440
|
+
# @param partitioner [String] name of the partitioner to use
|
|
441
|
+
# @return [Integer] partition number or RD_KAFKA_PARTITION_UA if unassigned
|
|
442
|
+
# @raise [Rdkafka::Config::ConfigError] when an unknown partitioner is specified
|
|
400
443
|
def self.partitioner(topic_ptr, str, partition_count, partitioner = "consistent_random")
|
|
401
444
|
# Return RD_KAFKA_PARTITION_UA(unassigned partition) when partition count is nil/zero.
|
|
402
|
-
return
|
|
445
|
+
return RD_KAFKA_PARTITION_UA unless partition_count&.nonzero?
|
|
403
446
|
|
|
404
447
|
str_ptr = str.empty? ? FFI::MemoryPointer::NULL : FFI::MemoryPointer.from_string(str)
|
|
405
448
|
method_name = PARTITIONERS.fetch(partitioner) do
|
|
@@ -410,7 +453,6 @@ module Rdkafka
|
|
|
410
453
|
end
|
|
411
454
|
|
|
412
455
|
# Create Topics
|
|
413
|
-
|
|
414
456
|
RD_KAFKA_ADMIN_OP_CREATETOPICS = 1 # rd_kafka_admin_op_t
|
|
415
457
|
RD_KAFKA_EVENT_CREATETOPICS_RESULT = 100 # rd_kafka_event_type_t
|
|
416
458
|
|
|
@@ -422,7 +464,6 @@ module Rdkafka
|
|
|
422
464
|
attach_function :rd_kafka_CreateTopics_result_topics, [:pointer, :pointer], :pointer, blocking: true
|
|
423
465
|
|
|
424
466
|
# Delete Topics
|
|
425
|
-
|
|
426
467
|
RD_KAFKA_ADMIN_OP_DELETETOPICS = 2 # rd_kafka_admin_op_t
|
|
427
468
|
RD_KAFKA_EVENT_DELETETOPICS_RESULT = 101 # rd_kafka_event_type_t
|
|
428
469
|
|
|
@@ -443,7 +484,6 @@ module Rdkafka
|
|
|
443
484
|
attach_function :rd_kafka_CreatePartitions_result_topics, [:pointer, :pointer], :pointer
|
|
444
485
|
|
|
445
486
|
# Delete Group
|
|
446
|
-
|
|
447
487
|
RD_KAFKA_ADMIN_OP_DELETEGROUPS = 7 # rd_kafka_admin_op_t
|
|
448
488
|
RD_KAFKA_EVENT_DELETEGROUPS_RESULT = 106 # rd_kafka_event_type_t
|
|
449
489
|
|
|
@@ -477,7 +517,6 @@ module Rdkafka
|
|
|
477
517
|
attach_function :rd_kafka_topic_result_name, [:pointer], :pointer
|
|
478
518
|
|
|
479
519
|
# Create Acls
|
|
480
|
-
|
|
481
520
|
RD_KAFKA_ADMIN_OP_CREATEACLS = 9
|
|
482
521
|
RD_KAFKA_EVENT_CREATEACLS_RESULT = 1024
|
|
483
522
|
|
|
@@ -486,7 +525,6 @@ module Rdkafka
|
|
|
486
525
|
attach_function :rd_kafka_CreateAcls_result_acls, [:pointer, :pointer], :pointer
|
|
487
526
|
|
|
488
527
|
# Delete Acls
|
|
489
|
-
|
|
490
528
|
RD_KAFKA_ADMIN_OP_DELETEACLS = 11
|
|
491
529
|
RD_KAFKA_EVENT_DELETEACLS_RESULT = 4096
|
|
492
530
|
|
|
@@ -497,7 +535,6 @@ module Rdkafka
|
|
|
497
535
|
attach_function :rd_kafka_DeleteAcls_result_response_matching_acls, [:pointer, :pointer], :pointer
|
|
498
536
|
|
|
499
537
|
# Describe Acls
|
|
500
|
-
|
|
501
538
|
RD_KAFKA_ADMIN_OP_DESCRIBEACLS = 10
|
|
502
539
|
RD_KAFKA_EVENT_DESCRIBEACLS_RESULT = 2048
|
|
503
540
|
|
|
@@ -519,7 +556,6 @@ module Rdkafka
|
|
|
519
556
|
attach_function :rd_kafka_AclBinding_destroy, [:pointer], :void
|
|
520
557
|
|
|
521
558
|
# rd_kafka_ResourceType_t - https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7307
|
|
522
|
-
|
|
523
559
|
RD_KAFKA_RESOURCE_ANY = 1
|
|
524
560
|
RD_KAFKA_RESOURCE_TOPIC = 2
|
|
525
561
|
RD_KAFKA_RESOURCE_GROUP = 3
|
|
@@ -527,14 +563,12 @@ module Rdkafka
|
|
|
527
563
|
RD_KAFKA_RESOURCE_TRANSACTIONAL_ID = 5
|
|
528
564
|
|
|
529
565
|
# rd_kafka_ResourcePatternType_t - https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7320
|
|
530
|
-
|
|
531
566
|
RD_KAFKA_RESOURCE_PATTERN_ANY = 1
|
|
532
567
|
RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
|
|
533
568
|
RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
|
|
534
569
|
RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
|
|
535
570
|
|
|
536
571
|
# rd_kafka_AclOperation_t - https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8403
|
|
537
|
-
|
|
538
572
|
RD_KAFKA_ACL_OPERATION_ANY = 1
|
|
539
573
|
RD_KAFKA_ACL_OPERATION_ALL = 2
|
|
540
574
|
RD_KAFKA_ACL_OPERATION_READ = 3
|
|
@@ -549,7 +583,6 @@ module Rdkafka
|
|
|
549
583
|
RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
|
|
550
584
|
|
|
551
585
|
# rd_kafka_AclPermissionType_t - https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
|
|
552
|
-
|
|
553
586
|
RD_KAFKA_ACL_PERMISSION_TYPE_ANY = 1
|
|
554
587
|
RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
|
|
555
588
|
RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
|
|
@@ -563,8 +596,8 @@ module Rdkafka
|
|
|
563
596
|
attach_function :rd_kafka_AclBinding_error, [:pointer], :pointer
|
|
564
597
|
|
|
565
598
|
|
|
566
|
-
#
|
|
567
|
-
class NativeError < FFI::Struct
|
|
599
|
+
# FFI struct for native error (rd_kafka_error_t)
|
|
600
|
+
class NativeError < FFI::Struct
|
|
568
601
|
layout :code, :int32,
|
|
569
602
|
:errstr, :pointer,
|
|
570
603
|
:fatal, :u_int8_t,
|