rdkafka 0.23.0-aarch64-linux-gnu

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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +267 -0
  3. data/Gemfile +5 -0
  4. data/MIT-LICENSE +22 -0
  5. data/README.md +179 -0
  6. data/Rakefile +96 -0
  7. data/docker-compose-ssl.yml +35 -0
  8. data/docker-compose.yml +25 -0
  9. data/ext/librdkafka.so +0 -0
  10. data/lib/rdkafka/abstract_handle.rb +116 -0
  11. data/lib/rdkafka/admin/acl_binding_result.rb +51 -0
  12. data/lib/rdkafka/admin/config_binding_result.rb +30 -0
  13. data/lib/rdkafka/admin/config_resource_binding_result.rb +18 -0
  14. data/lib/rdkafka/admin/create_acl_handle.rb +28 -0
  15. data/lib/rdkafka/admin/create_acl_report.rb +24 -0
  16. data/lib/rdkafka/admin/create_partitions_handle.rb +27 -0
  17. data/lib/rdkafka/admin/create_partitions_report.rb +6 -0
  18. data/lib/rdkafka/admin/create_topic_handle.rb +29 -0
  19. data/lib/rdkafka/admin/create_topic_report.rb +24 -0
  20. data/lib/rdkafka/admin/delete_acl_handle.rb +30 -0
  21. data/lib/rdkafka/admin/delete_acl_report.rb +23 -0
  22. data/lib/rdkafka/admin/delete_groups_handle.rb +28 -0
  23. data/lib/rdkafka/admin/delete_groups_report.rb +24 -0
  24. data/lib/rdkafka/admin/delete_topic_handle.rb +29 -0
  25. data/lib/rdkafka/admin/delete_topic_report.rb +24 -0
  26. data/lib/rdkafka/admin/describe_acl_handle.rb +30 -0
  27. data/lib/rdkafka/admin/describe_acl_report.rb +24 -0
  28. data/lib/rdkafka/admin/describe_configs_handle.rb +33 -0
  29. data/lib/rdkafka/admin/describe_configs_report.rb +54 -0
  30. data/lib/rdkafka/admin/incremental_alter_configs_handle.rb +33 -0
  31. data/lib/rdkafka/admin/incremental_alter_configs_report.rb +54 -0
  32. data/lib/rdkafka/admin.rb +832 -0
  33. data/lib/rdkafka/bindings.rb +565 -0
  34. data/lib/rdkafka/callbacks.rb +415 -0
  35. data/lib/rdkafka/config.rb +395 -0
  36. data/lib/rdkafka/consumer/headers.rb +79 -0
  37. data/lib/rdkafka/consumer/message.rb +86 -0
  38. data/lib/rdkafka/consumer/partition.rb +51 -0
  39. data/lib/rdkafka/consumer/topic_partition_list.rb +173 -0
  40. data/lib/rdkafka/consumer.rb +653 -0
  41. data/lib/rdkafka/error.rb +101 -0
  42. data/lib/rdkafka/helpers/oauth.rb +58 -0
  43. data/lib/rdkafka/helpers/time.rb +14 -0
  44. data/lib/rdkafka/metadata.rb +115 -0
  45. data/lib/rdkafka/native_kafka.rb +139 -0
  46. data/lib/rdkafka/producer/delivery_handle.rb +40 -0
  47. data/lib/rdkafka/producer/delivery_report.rb +46 -0
  48. data/lib/rdkafka/producer/partitions_count_cache.rb +216 -0
  49. data/lib/rdkafka/producer.rb +435 -0
  50. data/lib/rdkafka/version.rb +7 -0
  51. data/lib/rdkafka.rb +54 -0
  52. data/rdkafka.gemspec +92 -0
  53. data/renovate.json +80 -0
  54. metadata +255 -0
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rdkafka
4
+ class Consumer
5
+ # A list of topics with their partition information
6
+ class TopicPartitionList
7
+ # Create a topic partition list.
8
+ #
9
+ # @param data [Hash{String => nil,Partition}] The topic and partition data or nil to create an empty list
10
+ #
11
+ # @return [TopicPartitionList]
12
+ def initialize(data=nil)
13
+ @data = data || {}
14
+ end
15
+
16
+ # Number of items in the list
17
+ # @return [Integer]
18
+ def count
19
+ i = 0
20
+ @data.each do |_topic, partitions|
21
+ if partitions
22
+ i += partitions.count
23
+ else
24
+ i+= 1
25
+ end
26
+ end
27
+ i
28
+ end
29
+
30
+ # Whether this list is empty
31
+ # @return [Boolean]
32
+ def empty?
33
+ @data.empty?
34
+ end
35
+
36
+ # Add a topic with optionally partitions to the list.
37
+ # Calling this method multiple times for the same topic will overwrite the previous configuraton.
38
+ #
39
+ # @param topic [String] The topic's name
40
+ # @param partitions [Array<Integer>, Range<Integer>, Integer] The topic's partitions or partition count
41
+ #
42
+ # @return [nil]
43
+ #
44
+ # @example Add a topic with unassigned partitions
45
+ # tpl.add_topic("topic")
46
+ #
47
+ # @example Add a topic with assigned partitions
48
+ # tpl.add_topic("topic", (0..8))
49
+ #
50
+ # @example Add a topic with all topics up to a count
51
+ # tpl.add_topic("topic", 9)
52
+ #
53
+ def add_topic(topic, partitions=nil)
54
+ if partitions.nil?
55
+ @data[topic.to_s] = nil
56
+ else
57
+ if partitions.is_a? Integer
58
+ partitions = (0..partitions - 1)
59
+ end
60
+ @data[topic.to_s] = partitions.map { |p| Partition.new(p, nil, 0) }
61
+ end
62
+ end
63
+
64
+ # Add a topic with partitions and offsets set to the list
65
+ # Calling this method multiple times for the same topic will overwrite the previous configuraton.
66
+ #
67
+ # @param topic [String] The topic's name
68
+ # @param partitions_with_offsets [Hash<Integer, Integer>] The topic's partitions and offsets
69
+ # @param partitions_with_offsets [Array<Consumer::Partition>] The topic's partitions with offsets
70
+ # and metadata (if any)
71
+ #
72
+ # @return [nil]
73
+ def add_topic_and_partitions_with_offsets(topic, partitions_with_offsets)
74
+ @data[topic.to_s] = partitions_with_offsets.map do |p, o|
75
+ p.is_a?(Partition) ? p : Partition.new(p, o)
76
+ end
77
+ end
78
+
79
+ # Return a `Hash` with the topics as keys and and an array of partition information as the value if present.
80
+ #
81
+ # @return [Hash{String => Array<Partition>,nil}]
82
+ def to_h
83
+ @data
84
+ end
85
+
86
+ # Human readable representation of this list.
87
+ # @return [String]
88
+ def to_s
89
+ "<TopicPartitionList: #{to_h}>"
90
+ end
91
+
92
+ def ==(other)
93
+ self.to_h == other.to_h
94
+ end
95
+
96
+ # Create a new topic partition list based of a native one.
97
+ #
98
+ # @private
99
+ #
100
+ # @param pointer [FFI::Pointer] Optional pointer to an existing native list. Its contents will be copied.
101
+ #
102
+ # @return [TopicPartitionList]
103
+ def self.from_native_tpl(pointer)
104
+ # Data to be moved into the tpl
105
+ data = {}
106
+
107
+ # Create struct and copy its contents
108
+ native_tpl = Rdkafka::Bindings::TopicPartitionList.new(pointer)
109
+ native_tpl[:cnt].times do |i|
110
+ ptr = native_tpl[:elems] + (i * Rdkafka::Bindings::TopicPartition.size)
111
+ elem = Rdkafka::Bindings::TopicPartition.new(ptr)
112
+ if elem[:partition] == -1
113
+ data[elem[:topic]] = nil
114
+ else
115
+ partitions = data[elem[:topic]] || []
116
+ offset = if elem[:offset] == Rdkafka::Bindings::RD_KAFKA_OFFSET_INVALID
117
+ nil
118
+ else
119
+ elem[:offset]
120
+ end
121
+ partition = Partition.new(elem[:partition], offset, elem[:err])
122
+ partitions.push(partition)
123
+ data[elem[:topic]] = partitions
124
+ end
125
+ end
126
+
127
+ # Return the created object
128
+ TopicPartitionList.new(data)
129
+ end
130
+
131
+ # Create a native tpl with the contents of this object added.
132
+ #
133
+ # The pointer will be cleaned by `rd_kafka_topic_partition_list_destroy` when GC releases it.
134
+ #
135
+ # @private
136
+ # @return [FFI::Pointer]
137
+ def to_native_tpl
138
+ tpl = Rdkafka::Bindings.rd_kafka_topic_partition_list_new(count)
139
+
140
+ @data.each do |topic, partitions|
141
+ if partitions
142
+ partitions.each do |p|
143
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_add(
144
+ tpl,
145
+ topic,
146
+ p.partition
147
+ )
148
+
149
+ if p.offset
150
+ offset = p.offset.is_a?(Time) ? p.offset.to_f * 1_000 : p.offset
151
+
152
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_set_offset(
153
+ tpl,
154
+ topic,
155
+ p.partition,
156
+ offset
157
+ )
158
+ end
159
+ end
160
+ else
161
+ Rdkafka::Bindings.rd_kafka_topic_partition_list_add(
162
+ tpl,
163
+ topic,
164
+ -1
165
+ )
166
+ end
167
+ end
168
+
169
+ tpl
170
+ end
171
+ end
172
+ end
173
+ end