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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for describe topics operation result
|
|
6
|
+
class DescribeTopicsReport
|
|
7
|
+
include DescribeResultParsing
|
|
8
|
+
|
|
9
|
+
# Described topics, one per requested topic name. Each entry is a hash with:
|
|
10
|
+
# - `:name` [String] the topic name
|
|
11
|
+
# - `:topic_id` [String, nil] the topic id (KIP-516), base64 encoded, or `nil` when the
|
|
12
|
+
# topic could not be described
|
|
13
|
+
# - `:is_internal` [Boolean] whether the topic is internal (e.g. `__consumer_offsets`)
|
|
14
|
+
# - `:partitions` [Array<Hash>] each with `:partition` [Integer], `:leader` [Hash, nil] and
|
|
15
|
+
# `:replicas` / `:isr` [Array<Hash>]; nodes have `:id`, `:host`, `:port` and `:rack`
|
|
16
|
+
# - `:authorized_operations` [Array<Integer>, nil] `Bindings::RD_KAFKA_ACL_OPERATION_*`
|
|
17
|
+
# codes, `nil` unless requested with `include_authorized_operations: true`
|
|
18
|
+
# - `:error` [RdkafkaError, nil] per-topic error (e.g. `unknown_topic_or_part`), `nil`
|
|
19
|
+
# on success
|
|
20
|
+
# @return [Array<Hash>]
|
|
21
|
+
attr_reader :topics
|
|
22
|
+
|
|
23
|
+
# @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_DescribeTopics_result_t`
|
|
24
|
+
def initialize(result_ptr)
|
|
25
|
+
@topics = []
|
|
26
|
+
|
|
27
|
+
return if result_ptr.null?
|
|
28
|
+
|
|
29
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
30
|
+
array_ptr = Bindings.rd_kafka_DescribeTopics_result_topics(result_ptr, count_ptr)
|
|
31
|
+
|
|
32
|
+
return if array_ptr.null?
|
|
33
|
+
|
|
34
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |topic_ptr|
|
|
35
|
+
@topics << extract_topic(topic_ptr)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# @param topic_ptr [FFI::Pointer] pointer to a `rd_kafka_TopicDescription_t`
|
|
42
|
+
# @return [Hash]
|
|
43
|
+
def extract_topic(topic_ptr)
|
|
44
|
+
name_ptr = Bindings.rd_kafka_TopicDescription_name(topic_ptr)
|
|
45
|
+
operations_count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
name: name_ptr.null? ? nil : name_ptr.read_string,
|
|
49
|
+
topic_id: extract_topic_id(topic_ptr),
|
|
50
|
+
is_internal: Bindings.rd_kafka_TopicDescription_is_internal(topic_ptr) != 0,
|
|
51
|
+
partitions: extract_partitions(topic_ptr),
|
|
52
|
+
authorized_operations: extract_authorized_operations(
|
|
53
|
+
Bindings.rd_kafka_TopicDescription_authorized_operations(topic_ptr, operations_count_ptr),
|
|
54
|
+
operations_count_ptr
|
|
55
|
+
),
|
|
56
|
+
error: extract_error(topic_ptr)
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# librdkafka reports the zero UUID for a topic it could not describe
|
|
61
|
+
# @param topic_ptr [FFI::Pointer] pointer to a `rd_kafka_TopicDescription_t`
|
|
62
|
+
# @return [String, nil]
|
|
63
|
+
def extract_topic_id(topic_ptr)
|
|
64
|
+
uuid_ptr = Bindings.rd_kafka_TopicDescription_topic_id(topic_ptr)
|
|
65
|
+
|
|
66
|
+
return nil if uuid_ptr.null?
|
|
67
|
+
return nil if Bindings.rd_kafka_Uuid_most_significant_bits(uuid_ptr).zero? &&
|
|
68
|
+
Bindings.rd_kafka_Uuid_least_significant_bits(uuid_ptr).zero?
|
|
69
|
+
|
|
70
|
+
string_ptr = Bindings.rd_kafka_Uuid_base64str(uuid_ptr)
|
|
71
|
+
string_ptr.null? ? nil : string_ptr.read_string
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# @param topic_ptr [FFI::Pointer] pointer to a `rd_kafka_TopicDescription_t`
|
|
75
|
+
# @return [Array<Hash>]
|
|
76
|
+
def extract_partitions(topic_ptr)
|
|
77
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
78
|
+
array_ptr = Bindings.rd_kafka_TopicDescription_partitions(topic_ptr, count_ptr)
|
|
79
|
+
|
|
80
|
+
return [] if array_ptr.null?
|
|
81
|
+
|
|
82
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).map do |partition_ptr|
|
|
83
|
+
replicas_count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
84
|
+
isr_count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
partition: Bindings.rd_kafka_TopicPartitionInfo_partition(partition_ptr),
|
|
88
|
+
leader: extract_node(Bindings.rd_kafka_TopicPartitionInfo_leader(partition_ptr)),
|
|
89
|
+
replicas: extract_nodes(
|
|
90
|
+
Bindings.rd_kafka_TopicPartitionInfo_replicas(partition_ptr, replicas_count_ptr),
|
|
91
|
+
replicas_count_ptr
|
|
92
|
+
),
|
|
93
|
+
isr: extract_nodes(
|
|
94
|
+
Bindings.rd_kafka_TopicPartitionInfo_isr(partition_ptr, isr_count_ptr),
|
|
95
|
+
isr_count_ptr
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# The error is owned by the result, so it is copied and not destroyed here.
|
|
102
|
+
# @param topic_ptr [FFI::Pointer] pointer to a `rd_kafka_TopicDescription_t`
|
|
103
|
+
# @return [RdkafkaError, nil]
|
|
104
|
+
def extract_error(topic_ptr)
|
|
105
|
+
error_ptr = Bindings.rd_kafka_TopicDescription_error(topic_ptr)
|
|
106
|
+
|
|
107
|
+
return nil if error_ptr.null?
|
|
108
|
+
|
|
109
|
+
code = Bindings.rd_kafka_error_code(error_ptr)
|
|
110
|
+
|
|
111
|
+
return nil if code == Bindings::RD_KAFKA_RESP_ERR_NO_ERROR
|
|
112
|
+
|
|
113
|
+
string_ptr = Bindings.rd_kafka_error_string(error_ptr)
|
|
114
|
+
RdkafkaError.new(code, broker_message: string_ptr.null? ? nil : string_ptr.read_string)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for incremental alter configs operation
|
|
6
|
+
class IncrementalAlterConfigsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation.
|
|
11
|
+
def operation_name
|
|
12
|
+
"incremental alter configs"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [IncrementalAlterConfigsReport] report prepared by the background event callback
|
|
16
|
+
def create_result
|
|
17
|
+
prepared_result
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Raises an error if the operation failed
|
|
21
|
+
# @raise [RdkafkaError]
|
|
22
|
+
def raise_error
|
|
23
|
+
raise RdkafkaError.new(
|
|
24
|
+
self[:response],
|
|
25
|
+
broker_message: broker_message
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for incremental alter configs operation result
|
|
6
|
+
class IncrementalAlterConfigsReport
|
|
7
|
+
attr_reader :resources
|
|
8
|
+
|
|
9
|
+
# @param config_entries [FFI::Pointer] pointer to config entries array
|
|
10
|
+
# @param entry_count [Integer] number of config entries
|
|
11
|
+
def initialize(config_entries:, entry_count:)
|
|
12
|
+
@resources = []
|
|
13
|
+
|
|
14
|
+
return if config_entries == FFI::Pointer::NULL
|
|
15
|
+
|
|
16
|
+
config_entries
|
|
17
|
+
.read_array_of_pointer(entry_count)
|
|
18
|
+
.each { |config_resource_result_ptr| validate!(config_resource_result_ptr) }
|
|
19
|
+
.each do |config_resource_result_ptr|
|
|
20
|
+
config_resource_result = ConfigResourceBindingResult.new(config_resource_result_ptr)
|
|
21
|
+
|
|
22
|
+
pointer_to_size_t = FFI::MemoryPointer.new(:size_t)
|
|
23
|
+
configs_ptr = Bindings.rd_kafka_ConfigResource_configs(
|
|
24
|
+
config_resource_result_ptr,
|
|
25
|
+
pointer_to_size_t
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
configs_ptr
|
|
29
|
+
.read_array_of_pointer(pointer_to_size_t.read_int)
|
|
30
|
+
.map { |config_ptr| ConfigBindingResult.new(config_ptr) }
|
|
31
|
+
.each { |config_binding| config_resource_result.configs << config_binding }
|
|
32
|
+
|
|
33
|
+
@resources << config_resource_result
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# Validates the config resource result and raises an error if invalid
|
|
40
|
+
# @param config_resource_result_ptr [FFI::Pointer] pointer to the config resource result
|
|
41
|
+
# @raise [RdkafkaError] when the config resource has an error
|
|
42
|
+
def validate!(config_resource_result_ptr)
|
|
43
|
+
code = Bindings.rd_kafka_ConfigResource_error(config_resource_result_ptr)
|
|
44
|
+
|
|
45
|
+
return if code.zero?
|
|
46
|
+
|
|
47
|
+
raise(
|
|
48
|
+
RdkafkaError.new(
|
|
49
|
+
code,
|
|
50
|
+
Bindings.rd_kafka_ConfigResource_error_string(config_resource_result_ptr)
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for list consumer groups operation
|
|
6
|
+
class ListConsumerGroupsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation
|
|
11
|
+
def operation_name
|
|
12
|
+
"list consumer groups"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [ListConsumerGroupsReport] report prepared by the background event callback, with
|
|
16
|
+
# the listed consumer groups.
|
|
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,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for list consumer groups operation result
|
|
6
|
+
class ListConsumerGroupsReport
|
|
7
|
+
# Consumer groups listed cluster-wide. Each entry is a hash with:
|
|
8
|
+
# - `:group_id` [String] the consumer group id
|
|
9
|
+
# - `:is_simple_consumer_group` [Boolean] `true` for a "simple" consumer group - one that
|
|
10
|
+
# assigns partitions manually (via `assign`) and uses Kafka only for offset storage,
|
|
11
|
+
# rather than joining the group-management protocol and letting Kafka assign partitions
|
|
12
|
+
# and rebalance automatically (`subscribe`). Simple groups have no members from the
|
|
13
|
+
# broker's point of view, so they never rebalance.
|
|
14
|
+
# - `:state` [Integer] the group state as a `Bindings::RD_KAFKA_CONSUMER_GROUP_STATE_*`
|
|
15
|
+
# code, one of: `RD_KAFKA_CONSUMER_GROUP_STATE_UNKNOWN`,
|
|
16
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_PREPARING_REBALANCE`,
|
|
17
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_COMPLETING_REBALANCE`,
|
|
18
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_STABLE`, `RD_KAFKA_CONSUMER_GROUP_STATE_DEAD`,
|
|
19
|
+
# `RD_KAFKA_CONSUMER_GROUP_STATE_EMPTY`
|
|
20
|
+
# - `:state_name` [String] human-readable name of that state (e.g. `"Stable"`, `"Empty"`)
|
|
21
|
+
# @return [Array<Hash>]
|
|
22
|
+
attr_reader :groups
|
|
23
|
+
|
|
24
|
+
# Per-broker errors reported alongside the (partial) group listing. `ListConsumerGroups`
|
|
25
|
+
# fans out to every broker and returns valid groups and errors separately, so a broker
|
|
26
|
+
# being unreachable does not discard the groups the reachable brokers returned.
|
|
27
|
+
# @return [Array<RdkafkaError>]
|
|
28
|
+
attr_reader :errors
|
|
29
|
+
|
|
30
|
+
# @param result_ptr [FFI::Pointer] pointer to the `rd_kafka_ListConsumerGroups_result_t`
|
|
31
|
+
def initialize(result_ptr)
|
|
32
|
+
@groups = []
|
|
33
|
+
@errors = []
|
|
34
|
+
|
|
35
|
+
return if result_ptr.null?
|
|
36
|
+
|
|
37
|
+
extract_groups(result_ptr)
|
|
38
|
+
extract_errors(result_ptr)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# @param result_ptr [FFI::Pointer] pointer to the result
|
|
44
|
+
def extract_groups(result_ptr)
|
|
45
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
46
|
+
array_ptr = Bindings.rd_kafka_ListConsumerGroups_result_valid(result_ptr, count_ptr)
|
|
47
|
+
|
|
48
|
+
return if array_ptr.null?
|
|
49
|
+
|
|
50
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |listing_ptr|
|
|
51
|
+
state = Bindings.rd_kafka_ConsumerGroupListing_state(listing_ptr)
|
|
52
|
+
group_id_ptr = Bindings.rd_kafka_ConsumerGroupListing_group_id(listing_ptr)
|
|
53
|
+
state_name_ptr = Bindings.rd_kafka_consumer_group_state_name(state)
|
|
54
|
+
|
|
55
|
+
@groups << {
|
|
56
|
+
group_id: group_id_ptr.null? ? nil : group_id_ptr.read_string,
|
|
57
|
+
is_simple_consumer_group:
|
|
58
|
+
Bindings.rd_kafka_ConsumerGroupListing_is_simple_consumer_group(listing_ptr) != 0,
|
|
59
|
+
state: state,
|
|
60
|
+
state_name: state_name_ptr.null? ? nil : state_name_ptr.read_string
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @param result_ptr [FFI::Pointer] pointer to the result
|
|
66
|
+
def extract_errors(result_ptr)
|
|
67
|
+
count_ptr = FFI::MemoryPointer.new(:size_t)
|
|
68
|
+
array_ptr = Bindings.rd_kafka_ListConsumerGroups_result_errors(result_ptr, count_ptr)
|
|
69
|
+
|
|
70
|
+
return if array_ptr.null?
|
|
71
|
+
|
|
72
|
+
array_ptr.read_array_of_pointer(count_ptr.read(:size_t)).each do |error_ptr|
|
|
73
|
+
string_ptr = Bindings.rd_kafka_error_string(error_ptr)
|
|
74
|
+
|
|
75
|
+
@errors << RdkafkaError.new(
|
|
76
|
+
Bindings.rd_kafka_error_code(error_ptr),
|
|
77
|
+
broker_message: string_ptr.null? ? nil : string_ptr.read_string
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Handle for list offsets operation
|
|
6
|
+
class ListOffsetsHandle < AbstractHandle
|
|
7
|
+
layout :pending, :bool,
|
|
8
|
+
:response, :int
|
|
9
|
+
|
|
10
|
+
# @return [String] the name of the operation.
|
|
11
|
+
def operation_name
|
|
12
|
+
"list offsets"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [ListOffsetsReport] report prepared by the background event callback, with
|
|
16
|
+
# partition offset information.
|
|
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,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rdkafka
|
|
4
|
+
class Admin
|
|
5
|
+
# Report for list offsets operation result
|
|
6
|
+
class ListOffsetsReport
|
|
7
|
+
attr_reader :offsets
|
|
8
|
+
|
|
9
|
+
# @param result_infos [FFI::Pointer] pointer to result info array
|
|
10
|
+
# @param result_count [Integer] number of result info entries
|
|
11
|
+
def initialize(result_infos:, result_count:)
|
|
12
|
+
@offsets = []
|
|
13
|
+
|
|
14
|
+
return if result_infos.null?
|
|
15
|
+
|
|
16
|
+
result_infos
|
|
17
|
+
.read_array_of_pointer(result_count)
|
|
18
|
+
.each { |result_info_ptr| validate!(result_info_ptr) }
|
|
19
|
+
.each do |result_info_ptr|
|
|
20
|
+
tp_ptr = Bindings.rd_kafka_ListOffsetsResultInfo_topic_partition(result_info_ptr)
|
|
21
|
+
tp = Bindings::TopicPartition.new(tp_ptr)
|
|
22
|
+
timestamp = Bindings.rd_kafka_ListOffsetsResultInfo_timestamp(result_info_ptr)
|
|
23
|
+
leader_epoch = Bindings.rd_kafka_topic_partition_get_leader_epoch(tp_ptr)
|
|
24
|
+
|
|
25
|
+
@offsets << {
|
|
26
|
+
topic: tp[:topic],
|
|
27
|
+
partition: tp[:partition],
|
|
28
|
+
offset: tp[:offset],
|
|
29
|
+
timestamp: timestamp,
|
|
30
|
+
leader_epoch: (leader_epoch == -1) ? nil : leader_epoch
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# Validates the partition result and raises an error if invalid
|
|
38
|
+
# @param result_info_ptr [FFI::Pointer] pointer to the result info
|
|
39
|
+
# @raise [RdkafkaError] when the partition has an error, naming the failing partition
|
|
40
|
+
def validate!(result_info_ptr)
|
|
41
|
+
tp_ptr = Bindings.rd_kafka_ListOffsetsResultInfo_topic_partition(result_info_ptr)
|
|
42
|
+
tp = Bindings::TopicPartition.new(tp_ptr)
|
|
43
|
+
code = tp[:err]
|
|
44
|
+
|
|
45
|
+
return if code.zero?
|
|
46
|
+
|
|
47
|
+
raise RdkafkaError.new(
|
|
48
|
+
code,
|
|
49
|
+
"Error querying offsets for partition #{tp[:partition]} of '#{tp[:topic]}'"
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|