rdkafka 0.30.0-aarch64-linux-gnu → 0.31.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  3. data/README.md +1 -0
  4. data/docker-compose-ssl.yml +1 -0
  5. data/docker-compose.yml +1 -0
  6. data/ext/librdkafka.so +0 -0
  7. data/lib/rdkafka/admin/describe_cluster_handle.rb +31 -0
  8. data/lib/rdkafka/admin/describe_cluster_report.rb +48 -0
  9. data/lib/rdkafka/admin/describe_consumer_groups_handle.rb +31 -0
  10. data/lib/rdkafka/admin/describe_consumer_groups_report.rb +151 -0
  11. data/lib/rdkafka/admin/describe_result_parsing.rb +47 -0
  12. data/lib/rdkafka/admin/describe_topics_handle.rb +31 -0
  13. data/lib/rdkafka/admin/describe_topics_report.rb +118 -0
  14. data/lib/rdkafka/admin.rb +245 -0
  15. data/lib/rdkafka/bindings/admin/acls.rb +85 -0
  16. data/lib/rdkafka/bindings/admin/configs.rb +37 -0
  17. data/lib/rdkafka/bindings/admin/list_offsets.rb +26 -0
  18. data/lib/rdkafka/bindings/admin.rb +197 -0
  19. data/lib/rdkafka/bindings/callbacks.rb +100 -0
  20. data/lib/rdkafka/bindings/configuration.rb +50 -0
  21. data/lib/rdkafka/bindings/consumer.rb +83 -0
  22. data/lib/rdkafka/bindings/errors.rb +15 -0
  23. data/lib/rdkafka/bindings/handle.rb +16 -0
  24. data/lib/rdkafka/bindings/messages.rb +28 -0
  25. data/lib/rdkafka/bindings/metadata.rb +14 -0
  26. data/lib/rdkafka/bindings/polling.rb +17 -0
  27. data/lib/rdkafka/bindings/producer.rb +77 -0
  28. data/lib/rdkafka/bindings/structs.rb +62 -0
  29. data/lib/rdkafka/bindings.rb +12 -655
  30. data/lib/rdkafka/callbacks/describe_cluster_handler.rb +36 -0
  31. data/lib/rdkafka/callbacks/describe_consumer_groups_handler.rb +36 -0
  32. data/lib/rdkafka/callbacks/describe_topics_handler.rb +36 -0
  33. data/lib/rdkafka/callbacks.rb +10 -1
  34. data/lib/rdkafka/clients.rb +13 -46
  35. data/lib/rdkafka/consumer/message.rb +6 -9
  36. data/lib/rdkafka/producer/delivery_handle.rb +8 -2
  37. data/lib/rdkafka/producer/delivery_report.rb +51 -1
  38. data/lib/rdkafka/version.rb +3 -3
  39. data/lib/rdkafka.rb +10 -0
  40. data/package-lock.json +9 -9
  41. data/rdkafka.gemspec +1 -1
  42. data/renovate.json +3 -0
  43. metadata +26 -2
@@ -84,660 +84,17 @@ module Rdkafka
84
84
  # librdkafka components without initializing the client
85
85
  # See: https://github.com/confluentinc/librdkafka/issues/4590
86
86
  attach_function :rd_kafka_global_init, [], :void
87
-
88
- # Polling
89
-
90
- attach_function :rd_kafka_flush, [:pointer, :int], :int, blocking: true
91
- attach_function :rd_kafka_poll, [:pointer, :int], :int, blocking: true
92
- attach_function :rd_kafka_outq_len, [:pointer], :int, blocking: true
93
-
94
- # Non-blocking poll variants (do not release GVL)
95
- # These are more efficient for poll(0) calls in fiber schedulers where GVL
96
- # release/reacquire overhead is wasteful since we don't expect to wait.
97
- # Uses the same underlying C function but with blocking: false to skip GVL release.
98
- attach_function :rd_kafka_poll_nb, :rd_kafka_poll, [:pointer, :int], :int, blocking: false
99
-
100
- # Metadata
101
-
102
- attach_function :rd_kafka_name, [:pointer], :string
103
- attach_function :rd_kafka_memberid, [:pointer], :pointer, blocking: true
104
- attach_function :rd_kafka_clusterid, [:pointer, :int], :pointer, blocking: true
105
- attach_function :rd_kafka_mem_free, [:pointer, :pointer], :void
106
- attach_function :rd_kafka_metadata, [:pointer, :int, :pointer, :pointer, :int], :int, blocking: true
107
- attach_function :rd_kafka_metadata_destroy, [:pointer], :void, blocking: true
108
-
109
- # FFI struct representing a Kafka message (rd_kafka_message_t)
110
- class Message < FFI::Struct
111
- layout :err, :int,
112
- :rkt, :pointer,
113
- :partition, :int32,
114
- :payload, :pointer,
115
- :len, :size_t,
116
- :key, :pointer,
117
- :key_len, :size_t,
118
- :offset, :int64,
119
- :_private, :pointer
120
- end
121
-
122
- attach_function :rd_kafka_message_destroy, [:pointer], :void
123
- attach_function :rd_kafka_message_timestamp, [:pointer, :pointer], :int64
124
- attach_function :rd_kafka_topic_new, [:pointer, :string, :pointer], :pointer
125
- attach_function :rd_kafka_topic_destroy, [:pointer], :pointer
126
- attach_function :rd_kafka_topic_name, [:pointer], :string
127
-
128
- # FFI struct representing a topic partition (rd_kafka_topic_partition_t)
129
- class TopicPartition < FFI::Struct
130
- layout :topic, :string,
131
- :partition, :int32,
132
- :offset, :int64,
133
- :metadata, :pointer,
134
- :metadata_size, :size_t,
135
- :opaque, :pointer,
136
- :err, :int,
137
- :_private, :pointer
138
- end
139
-
140
- # FFI struct representing a topic partition list (rd_kafka_topic_partition_list_t)
141
- class TopicPartitionList < FFI::Struct
142
- layout :cnt, :int,
143
- :size, :int,
144
- :elems, :pointer
145
- end
146
-
147
- attach_function :rd_kafka_topic_partition_list_new, [:int32], :pointer
148
- attach_function :rd_kafka_topic_partition_list_add, [:pointer, :string, :int32], :pointer
149
- attach_function :rd_kafka_topic_partition_list_set_offset, [:pointer, :string, :int32, :int64], :void
150
- attach_function :rd_kafka_topic_partition_list_destroy, [:pointer], :void
151
- attach_function :rd_kafka_topic_partition_list_copy, [:pointer], :pointer
152
-
153
- # FFI struct representing a config resource (rd_kafka_ConfigResource_t)
154
- # Structs for management of configurations. Each configuration is attached to a resource
155
- # and one resource can have many configuration details. Each resource will also have
156
- # separate errors results if obtaining configuration was not possible for any reason
157
- class ConfigResource < FFI::Struct
158
- layout :type, :int,
159
- :name, :string
160
- end
161
-
162
- attach_function :rd_kafka_DescribeConfigs, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
163
- attach_function :rd_kafka_ConfigResource_new, [:int32, :pointer], :pointer
164
- attach_function :rd_kafka_ConfigResource_destroy, [:pointer], :void
165
- attach_function :rd_kafka_ConfigResource_destroy_array, [:pointer, :int32], :void
166
- attach_function :rd_kafka_event_DescribeConfigs_result, [:pointer], :pointer
167
- attach_function :rd_kafka_DescribeConfigs_result_resources, [:pointer, :pointer], :pointer
168
- attach_function :rd_kafka_ConfigResource_configs, [:pointer, :pointer], :pointer
169
- attach_function :rd_kafka_ConfigEntry_name, [:pointer], :string
170
- attach_function :rd_kafka_ConfigEntry_value, [:pointer], :string
171
- attach_function :rd_kafka_ConfigEntry_is_read_only, [:pointer], :int
172
- attach_function :rd_kafka_ConfigEntry_is_default, [:pointer], :int
173
- attach_function :rd_kafka_ConfigEntry_is_sensitive, [:pointer], :int
174
- attach_function :rd_kafka_ConfigEntry_is_synonym, [:pointer], :int
175
- attach_function :rd_kafka_ConfigEntry_synonyms, [:pointer, :pointer], :pointer
176
- attach_function :rd_kafka_ConfigResource_error, [:pointer], :int
177
- attach_function :rd_kafka_ConfigResource_error_string, [:pointer], :string
178
- attach_function :rd_kafka_IncrementalAlterConfigs, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
179
- attach_function :rd_kafka_IncrementalAlterConfigs_result_resources, [:pointer, :pointer], :pointer
180
- attach_function :rd_kafka_ConfigResource_add_incremental_config, [:pointer, :string, :int32, :string], :pointer
181
- attach_function :rd_kafka_event_IncrementalAlterConfigs_result, [:pointer], :pointer
182
-
183
- RD_KAFKA_ADMIN_OP_DESCRIBECONFIGS = 5
184
- RD_KAFKA_EVENT_DESCRIBECONFIGS_RESULT = 104
185
-
186
- RD_KAFKA_ADMIN_OP_INCREMENTALALTERCONFIGS = 16
187
- RD_KAFKA_EVENT_INCREMENTALALTERCONFIGS_RESULT = 131072
188
-
189
- RD_KAFKA_ALTER_CONFIG_OP_TYPE_SET = 0
190
- RD_KAFKA_ALTER_CONFIG_OP_TYPE_DELETE = 1
191
- RD_KAFKA_ALTER_CONFIG_OP_TYPE_APPEND = 2
192
- RD_KAFKA_ALTER_CONFIG_OP_TYPE_SUBTRACT = 3
193
-
194
- # List Offsets
195
- RD_KAFKA_ADMIN_OP_LISTOFFSETS = 21
196
- RD_KAFKA_EVENT_LISTOFFSETS_RESULT = 0x400000
197
-
198
- # rd_kafka_IsolationLevel_t
199
- RD_KAFKA_ISOLATION_LEVEL_READ_UNCOMMITTED = 0
200
- RD_KAFKA_ISOLATION_LEVEL_READ_COMMITTED = 1
201
-
202
- # rd_kafka_OffsetSpec_t
203
- RD_KAFKA_OFFSET_SPEC_MAX_TIMESTAMP = -3
204
- RD_KAFKA_OFFSET_SPEC_EARLIEST = -2
205
- RD_KAFKA_OFFSET_SPEC_LATEST = -1
206
-
207
- attach_function :rd_kafka_ListOffsets, [:pointer, :pointer, :pointer, :pointer], :void, blocking: true
208
- attach_function :rd_kafka_event_ListOffsets_result, [:pointer], :pointer
209
- attach_function :rd_kafka_ListOffsets_result_infos, [:pointer, :pointer], :pointer
210
- attach_function :rd_kafka_ListOffsetsResultInfo_topic_partition, [:pointer], :pointer
211
- attach_function :rd_kafka_ListOffsetsResultInfo_timestamp, [:pointer], :int64
212
- attach_function :rd_kafka_AdminOptions_set_isolation_level, [:pointer, :int], :pointer
213
- attach_function :rd_kafka_topic_partition_get_leader_epoch, [:pointer], :int32
214
-
215
- # FFI struct for error description (rd_kafka_err_desc)
216
- class NativeErrorDesc < FFI::Struct
217
- layout :code, :int,
218
- :name, :pointer,
219
- :desc, :pointer
220
- end
221
-
222
- attach_function :rd_kafka_err2name, [:int], :string
223
- attach_function :rd_kafka_err2str, [:int], :string
224
- attach_function :rd_kafka_error_is_fatal, [:pointer], :int
225
- attach_function :rd_kafka_error_is_retriable, [:pointer], :int
226
- attach_function :rd_kafka_error_txn_requires_abort, [:pointer], :int
227
- attach_function :rd_kafka_error_destroy, [:pointer], :void
228
- attach_function :rd_kafka_get_err_descs, [:pointer, :pointer], :void
229
-
230
- # Configuration
231
-
232
- enum :kafka_config_response, [
233
- :config_unknown, -2,
234
- :config_invalid, -1,
235
- :config_ok, 0
236
- ]
237
-
238
- attach_function :rd_kafka_conf_new, [], :pointer
239
- attach_function :rd_kafka_conf_set, [:pointer, :string, :string, :pointer, :int], :kafka_config_response
240
- attach_function :rd_kafka_conf_get, [:pointer, :string, :pointer, :pointer], :kafka_config_response
241
- attach_function :rd_kafka_conf, [:pointer], :pointer
242
- attach_function :rd_kafka_conf_dump, [:pointer, :pointer], :pointer
243
- attach_function :rd_kafka_conf_dump_free, [:pointer, :size_t], :void
244
- attach_function :rd_kafka_conf_destroy, [:pointer], :void
245
- callback :log_cb, [:pointer, :int, :string, :string], :void
246
- attach_function :rd_kafka_conf_set_log_cb, [:pointer, :log_cb], :void
247
- attach_function :rd_kafka_conf_set_opaque, [:pointer, :pointer], :void
248
- callback :stats_cb, [:pointer, :string, :int, :pointer], :int
249
- attach_function :rd_kafka_conf_set_stats_cb, [:pointer, :stats_cb], :void
250
- callback :error_cb, [:pointer, :int, :string, :pointer], :void
251
- attach_function :rd_kafka_conf_set_error_cb, [:pointer, :error_cb], :void
252
- attach_function :rd_kafka_rebalance_protocol, [:pointer], :string
253
- callback :oauthbearer_token_refresh_cb, [:pointer, :string, :pointer], :void
254
- attach_function :rd_kafka_conf_set_oauthbearer_token_refresh_cb, [:pointer, :oauthbearer_token_refresh_cb], :void
255
- attach_function :rd_kafka_oauthbearer_set_token, [:pointer, :string, :int64, :pointer, :pointer, :int, :pointer, :int], :int
256
- attach_function :rd_kafka_oauthbearer_set_token_failure, [:pointer, :string], :int
257
- # Log queue
258
- attach_function :rd_kafka_set_log_queue, [:pointer, :pointer], :void
259
- attach_function :rd_kafka_queue_get_main, [:pointer], :pointer
260
- attach_function :rd_kafka_queue_get_background, [:pointer], :pointer
261
-
262
- # Queue IO Event Support - for fiber scheduler integration
263
- # Enables notifications to a custom FD when queue transitions from empty to non-empty
264
- # Arguments:
265
- # - queue (rd_kafka_queue_t*) - the queue to monitor
266
- # - fd (int) - file descriptor to write to (provide your own pipe/eventfd)
267
- # - payload (const void*) - data to write to fd
268
- # - size (size_t) - size of payload
269
- attach_function :rd_kafka_queue_io_event_enable, [:pointer, :int, :pointer, :size_t], :void
270
- # Per topic configs
271
- attach_function :rd_kafka_topic_conf_new, [], :pointer
272
- attach_function :rd_kafka_topic_conf_destroy, [:pointer], :void
273
- attach_function :rd_kafka_topic_conf_set, [:pointer, :string, :string, :pointer, :int], :kafka_config_response
274
-
275
- LogCallback = FFI::Function.new(
276
- :void, [:pointer, :int, :string, :string]
277
- ) do |_client_ptr, level, _level_string, line|
278
- severity = case level
279
- when 0, 1, 2
280
- Logger::FATAL
281
- when 3
282
- Logger::ERROR
283
- when 4
284
- Logger::WARN
285
- when 5, 6
286
- Logger::INFO
287
- when 7
288
- Logger::DEBUG
289
- else
290
- Logger::UNKNOWN
291
- end
292
-
293
- Rdkafka::Config.ensure_log_thread
294
- Rdkafka::Config.log_queue << [severity, "rdkafka: #{line}"]
295
- end
296
-
297
- StatsCallback = FFI::Function.new(
298
- :int, [:pointer, :string, :int, :pointer]
299
- ) do |_client_ptr, json, _json_len, _opaque|
300
- if Rdkafka::Config.statistics_callback
301
- stats = JSON.parse(json)
302
-
303
- # If user requested statistics callbacks, we can use the statistics data to get the
304
- # partitions count for each topic when this data is published. That way we do not have
305
- # to query this information when user is using `partition_key`. This takes around 0.02ms
306
- # every statistics interval period (most likely every 5 seconds) and saves us from making
307
- # any queries to the cluster for the partition count.
308
- #
309
- # One edge case is if user would set the `statistics.interval.ms` much higher than the
310
- # default current partition count refresh (30 seconds). This is taken care of as the lack
311
- # of reporting to the partitions cache will cause cache expire and blocking refresh.
312
- #
313
- # If user sets `topic.metadata.refresh.interval.ms` too high this is on the user.
314
- #
315
- # Since this cache is shared, having few consumers and/or producers in one process will
316
- # automatically improve the querying times even with low refresh times.
317
- (stats["topics"] || EMPTY_HASH).each do |topic_name, details|
318
- partitions_count = details["partitions"].keys.count { |k| !(k == RD_KAFKA_PARTITION_UA_STR) }
319
-
320
- next unless partitions_count.positive?
321
-
322
- Rdkafka::Producer.partitions_count_cache.set(topic_name, partitions_count)
323
- end
324
-
325
- Rdkafka::Config.statistics_callback.call(stats)
326
- end
327
-
328
- # Return 0 so librdkafka frees the json string
329
- RD_KAFKA_RESP_ERR_NO_ERROR
330
- end
331
-
332
- ErrorCallback = FFI::Function.new(
333
- :void, [:pointer, :int, :string, :pointer]
334
- ) do |client_ptr, err_code, reason, _opaque|
335
- if Rdkafka::Config.error_callback
336
- instance_name = client_ptr.null? ? nil : Rdkafka::Bindings.rd_kafka_name(client_ptr)
337
- error = Rdkafka::RdkafkaError.new(err_code, broker_message: reason, instance_name: instance_name)
338
- error.set_backtrace(caller)
339
- Rdkafka::Config.error_callback.call(error)
340
- end
341
- end
342
-
343
- # The OAuth callback is currently global and contextless. This means that the callback will be
344
- # called for all instances, and the callback must be able to determine to which instance it is
345
- # associated. The instance name will be provided in the callback, allowing the callback to
346
- # reference the correct instance.
347
- #
348
- # An example of how to use the instance name in the callback is given below.
349
- # The `refresh_token` is configured as the `oauthbearer_token_refresh_callback`.
350
- # `instances` is a map of client names to client instances, maintained by the user.
351
- #
352
- # ```
353
- # def refresh_token(config, client_name)
354
- # client = instances[client_name]
355
- # client.oauthbearer_set_token(
356
- # token: 'new-token-value',
357
- # lifetime_ms: token-lifetime-ms,
358
- # principal_name: 'principal-name'
359
- # )
360
- # end
361
- # ```
362
- OAuthbearerTokenRefreshCallback = FFI::Function.new(
363
- :void, [:pointer, :string, :pointer]
364
- ) do |client_ptr, config, _opaque|
365
- if Rdkafka::Config.oauthbearer_token_refresh_callback && !client_ptr.null?
366
- Rdkafka::Config.oauthbearer_token_refresh_callback.call(config, Rdkafka::Bindings.rd_kafka_name(client_ptr))
367
- end
368
- end
369
-
370
- # Handle
371
-
372
- enum :kafka_type, [
373
- :rd_kafka_producer,
374
- :rd_kafka_consumer
375
- ]
376
-
377
- attach_function :rd_kafka_new, [:kafka_type, :pointer, :pointer, :int], :pointer
378
-
379
- attach_function :rd_kafka_destroy, [:pointer], :void
380
-
381
- # Consumer
382
-
383
- attach_function :rd_kafka_subscribe, [:pointer, :pointer], :int, blocking: true
384
- attach_function :rd_kafka_unsubscribe, [:pointer], :int, blocking: true
385
- attach_function :rd_kafka_subscription, [:pointer, :pointer], :int, blocking: true
386
- attach_function :rd_kafka_assign, [:pointer, :pointer], :int, blocking: true
387
- attach_function :rd_kafka_incremental_assign, [:pointer, :pointer], :int, blocking: true
388
- attach_function :rd_kafka_incremental_unassign, [:pointer, :pointer], :int, blocking: true
389
- attach_function :rd_kafka_assignment, [:pointer, :pointer], :int, blocking: true
390
- attach_function :rd_kafka_assignment_lost, [:pointer], :int, blocking: true
391
- attach_function :rd_kafka_committed, [:pointer, :pointer, :int], :int, blocking: true
392
- attach_function :rd_kafka_commit, [:pointer, :pointer, :bool], :int, blocking: true
393
- attach_function :rd_kafka_poll_set_consumer, [:pointer], :void, blocking: true
394
- attach_function :rd_kafka_consumer_poll, [:pointer, :int], :pointer, blocking: true
395
- # Non-blocking consumer poll variant (does not release GVL)
396
- # More efficient for poll(0) calls in fiber schedulers.
397
- attach_function :rd_kafka_consumer_poll_nb, :rd_kafka_consumer_poll, [:pointer, :int], :pointer, blocking: false
398
- attach_function :rd_kafka_consumer_close, [:pointer], :void, blocking: true
399
- attach_function :rd_kafka_queue_get_consumer, [:pointer], :pointer
400
- attach_function :rd_kafka_consume_batch_queue, [:pointer, :int, :pointer, :size_t], :ssize_t, blocking: true
401
- attach_function :rd_kafka_consume_batch_queue_nb, :rd_kafka_consume_batch_queue, [:pointer, :int, :pointer, :size_t], :ssize_t, blocking: false
402
- attach_function :rd_kafka_offsets_store, [:pointer, :pointer], :int, blocking: true
403
- attach_function :rd_kafka_pause_partitions, [:pointer, :pointer], :int, blocking: true
404
- attach_function :rd_kafka_resume_partitions, [:pointer, :pointer], :int, blocking: true
405
- attach_function :rd_kafka_seek, [:pointer, :int32, :int64, :int], :int, blocking: true
406
- attach_function :rd_kafka_offsets_for_times, [:pointer, :pointer, :int], :int, blocking: true
407
- attach_function :rd_kafka_position, [:pointer, :pointer], :int, blocking: true
408
- # those two are used for eos support
409
- attach_function :rd_kafka_consumer_group_metadata, [:pointer], :pointer, blocking: true
410
- attach_function :rd_kafka_consumer_group_metadata_destroy, [:pointer], :void, blocking: true
411
-
412
- # Headers
413
- attach_function :rd_kafka_header_get_all, [:pointer, :size_t, :pointer, :pointer, SizePtr], :int
414
- attach_function :rd_kafka_message_headers, [:pointer, :pointer], :int
415
-
416
- # Rebalance
417
-
418
- callback :rebalance_cb_function, [:pointer, :int, :pointer, :pointer], :void
419
- attach_function :rd_kafka_conf_set_rebalance_cb, [:pointer, :rebalance_cb_function], :void, blocking: true
420
-
421
- RebalanceCallback = FFI::Function.new(
422
- :void, [:pointer, :int, :pointer, :pointer]
423
- ) do |client_ptr, code, partitions_ptr, opaque_ptr|
424
- case code
425
- when RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
426
- if Rdkafka::Bindings.rd_kafka_rebalance_protocol(client_ptr) == "COOPERATIVE"
427
- Rdkafka::Bindings.rd_kafka_incremental_assign(client_ptr, partitions_ptr)
428
- else
429
- Rdkafka::Bindings.rd_kafka_assign(client_ptr, partitions_ptr)
430
- end
431
- else # RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS or errors
432
- if Rdkafka::Bindings.rd_kafka_rebalance_protocol(client_ptr) == "COOPERATIVE"
433
- Rdkafka::Bindings.rd_kafka_incremental_unassign(client_ptr, partitions_ptr)
434
- else
435
- Rdkafka::Bindings.rd_kafka_assign(client_ptr, FFI::Pointer::NULL)
436
- end
437
- end
438
-
439
- opaque = Rdkafka::Config.opaques[opaque_ptr.to_i]
440
- return unless opaque
441
-
442
- tpl = Rdkafka::Consumer::TopicPartitionList.from_native_tpl(partitions_ptr).freeze
443
- begin
444
- case code
445
- when RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS
446
- opaque.call_on_partitions_assigned(tpl)
447
- when RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS
448
- opaque.call_on_partitions_revoked(tpl)
449
- end
450
- rescue Exception => err
451
- Rdkafka::Config.logger.error("Unhandled exception: #{err.class} - #{err.message}")
452
- end
453
- end
454
-
455
- # Stats
456
-
457
- attach_function :rd_kafka_query_watermark_offsets, [:pointer, :string, :int, :pointer, :pointer, :int], :int, blocking: true
458
-
459
- # Producer
460
- RD_KAFKA_VTYPE_END = 0
461
- RD_KAFKA_VTYPE_TOPIC = 1
462
- RD_KAFKA_VTYPE_RKT = 2
463
- RD_KAFKA_VTYPE_PARTITION = 3
464
- RD_KAFKA_VTYPE_VALUE = 4
465
- RD_KAFKA_VTYPE_KEY = 5
466
- RD_KAFKA_VTYPE_OPAQUE = 6
467
- RD_KAFKA_VTYPE_MSGFLAGS = 7
468
- RD_KAFKA_VTYPE_TIMESTAMP = 8
469
- RD_KAFKA_VTYPE_HEADER = 9
470
- RD_KAFKA_VTYPE_HEADERS = 10
471
- RD_KAFKA_PURGE_F_QUEUE = 1
472
- RD_KAFKA_PURGE_F_INFLIGHT = 2
473
-
474
- RD_KAFKA_MSG_F_COPY = 0x2
475
-
476
- attach_function :rd_kafka_producev, [:pointer, :varargs], :int, blocking: true
477
- attach_function :rd_kafka_purge, [:pointer, :int], :int, blocking: true
478
- callback :delivery_cb, [:pointer, :pointer, :pointer], :void
479
- attach_function :rd_kafka_conf_set_dr_msg_cb, [:pointer, :delivery_cb], :void
480
-
481
- # Hash mapping partitioner names to their FFI function symbols
482
- # @return [Hash{String => Symbol}]
483
- PARTITIONERS = %w[random consistent consistent_random murmur2 murmur2_random fnv1a fnv1a_random].each_with_object({}) do |name, hsh|
484
- method_name = :"rd_kafka_msg_partitioner_#{name}"
485
- attach_function method_name, [:pointer, :pointer, :size_t, :int32, :pointer, :pointer], :int32
486
- hsh[name] = method_name
487
- end
488
-
489
- # Calculates the partition for a message based on the partitioner
490
- #
491
- # @param topic_ptr [FFI::Pointer] pointer to the topic handle
492
- # @param str [String] the partition key string
493
- # @param partition_count [Integer, nil] number of partitions
494
- # @param partitioner [String] name of the partitioner to use
495
- # @return [Integer] partition number or RD_KAFKA_PARTITION_UA if unassigned
496
- # @raise [Rdkafka::Config::ConfigError] when an unknown partitioner is specified
497
- def self.partitioner(topic_ptr, str, partition_count, partitioner = "consistent_random")
498
- # Return RD_KAFKA_PARTITION_UA(unassigned partition) when partition count is nil/zero.
499
- return RD_KAFKA_PARTITION_UA unless partition_count&.nonzero?
500
-
501
- str_ptr = str.empty? ? FFI::MemoryPointer::NULL : FFI::MemoryPointer.from_string(str)
502
- method_name = PARTITIONERS.fetch(partitioner) do
503
- raise Rdkafka::Config::ConfigError.new("Unknown partitioner: #{partitioner}")
504
- end
505
-
506
- public_send(method_name, topic_ptr, str_ptr, partition_key_length(str), partition_count, nil, nil)
507
- end
508
-
509
- # Partition key length as the character count (legacy default).
510
- #
511
- # @param str [String] the partition key string
512
- # @return [Integer]
513
- def self.partition_key_size(str)
514
- str.size
515
- end
516
-
517
- # Partition key length as the byte count, which is what librdkafka hashes (UTF-8 bytes copied
518
- # into the key pointer) and what other Kafka clients use.
519
- #
520
- # @param str [String] the partition key string
521
- # @return [Integer]
522
- def self.partition_key_bytesize(str)
523
- str.bytesize
524
- end
525
-
526
- # Length of the partition key passed to librdkafka. Aliased to one of the methods above by
527
- # `Rdkafka::Config.partitioner_key_uses_bytesize=`, so the per-message path does not check the
528
- # setting on every call.
529
- singleton_class.alias_method :partition_key_length, :partition_key_size
530
-
531
- # Create Topics
532
- RD_KAFKA_ADMIN_OP_CREATETOPICS = 1 # rd_kafka_admin_op_t
533
- RD_KAFKA_EVENT_CREATETOPICS_RESULT = 100 # rd_kafka_event_type_t
534
-
535
- attach_function :rd_kafka_CreateTopics, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
536
- attach_function :rd_kafka_NewTopic_new, [:pointer, :size_t, :size_t, :pointer, :size_t], :pointer, blocking: true
537
- attach_function :rd_kafka_NewTopic_set_config, [:pointer, :string, :string], :int32, blocking: true
538
- attach_function :rd_kafka_NewTopic_destroy, [:pointer], :void, blocking: true
539
- attach_function :rd_kafka_event_CreateTopics_result, [:pointer], :pointer, blocking: true
540
- attach_function :rd_kafka_CreateTopics_result_topics, [:pointer, :pointer], :pointer, blocking: true
541
-
542
- # Delete Topics
543
- RD_KAFKA_ADMIN_OP_DELETETOPICS = 2 # rd_kafka_admin_op_t
544
- RD_KAFKA_EVENT_DELETETOPICS_RESULT = 101 # rd_kafka_event_type_t
545
-
546
- attach_function :rd_kafka_DeleteTopics, [:pointer, :pointer, :size_t, :pointer, :pointer], :int32, blocking: true
547
- attach_function :rd_kafka_DeleteTopic_new, [:pointer], :pointer, blocking: true
548
- attach_function :rd_kafka_DeleteTopic_destroy, [:pointer], :void, blocking: true
549
- attach_function :rd_kafka_event_DeleteTopics_result, [:pointer], :pointer, blocking: true
550
- attach_function :rd_kafka_DeleteTopics_result_topics, [:pointer, :pointer], :pointer, blocking: true
551
-
552
- # Create partitions
553
- RD_KAFKA_ADMIN_OP_CREATEPARTITIONS = 3
554
- RD_KAFKA_ADMIN_OP_CREATEPARTITIONS_RESULT = 102
555
-
556
- attach_function :rd_kafka_CreatePartitions, [:pointer, :pointer, :size_t, :pointer, :pointer], :void
557
- attach_function :rd_kafka_NewPartitions_new, %i[pointer size_t pointer size_t], :pointer
558
- attach_function :rd_kafka_NewPartitions_destroy, [:pointer], :void
559
- attach_function :rd_kafka_event_CreatePartitions_result, [:pointer], :pointer
560
- attach_function :rd_kafka_CreatePartitions_result_topics, [:pointer, :pointer], :pointer
561
-
562
- # Delete Group
563
- RD_KAFKA_ADMIN_OP_DELETEGROUPS = 7 # rd_kafka_admin_op_t
564
- RD_KAFKA_EVENT_DELETEGROUPS_RESULT = 106 # rd_kafka_event_type_t
565
-
566
- attach_function :rd_kafka_DeleteGroups, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
567
- attach_function :rd_kafka_DeleteGroup_new, [:pointer], :pointer, blocking: true
568
- attach_function :rd_kafka_DeleteGroup_destroy, [:pointer], :void, blocking: true
569
- attach_function :rd_kafka_event_DeleteGroups_result, [:pointer], :pointer, blocking: true # rd_kafka_event_t* => rd_kafka_DeleteGroups_result_t*
570
- attach_function :rd_kafka_DeleteGroups_result_groups, [:pointer, :pointer], :pointer, blocking: true # rd_kafka_DeleteGroups_result_t*, size_t* => rd_kafka_group_result_t**
571
-
572
- # Alter Consumer Group Offsets
573
- RD_KAFKA_ADMIN_OP_ALTERCONSUMERGROUPOFFSETS = 15 # rd_kafka_admin_op_t
574
- RD_KAFKA_EVENT_ALTERCONSUMERGROUPOFFSETS_RESULT = 0x10000 # rd_kafka_event_type_t
575
-
576
- attach_function :rd_kafka_AlterConsumerGroupOffsets, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
577
- attach_function :rd_kafka_AlterConsumerGroupOffsets_new, [:pointer, :pointer], :pointer, blocking: true # const char*, const rd_kafka_topic_partition_list_t* => rd_kafka_AlterConsumerGroupOffsets_t*
578
- attach_function :rd_kafka_AlterConsumerGroupOffsets_destroy, [:pointer], :void, blocking: true
579
- attach_function :rd_kafka_event_AlterConsumerGroupOffsets_result, [:pointer], :pointer, blocking: true # rd_kafka_event_t* => rd_kafka_AlterConsumerGroupOffsets_result_t*
580
- attach_function :rd_kafka_AlterConsumerGroupOffsets_result_groups, [:pointer, :pointer], :pointer, blocking: true # rd_kafka_AlterConsumerGroupOffsets_result_t*, size_t* => rd_kafka_group_result_t**
581
-
582
- # Delete Consumer Group Offsets
583
- RD_KAFKA_ADMIN_OP_DELETECONSUMERGROUPOFFSETS = 8 # rd_kafka_admin_op_t
584
- RD_KAFKA_EVENT_DELETECONSUMERGROUPOFFSETS_RESULT = 107 # rd_kafka_event_type_t
585
-
586
- attach_function :rd_kafka_DeleteConsumerGroupOffsets, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
587
- attach_function :rd_kafka_DeleteConsumerGroupOffsets_new, [:pointer, :pointer], :pointer, blocking: true # const char*, const rd_kafka_topic_partition_list_t* => rd_kafka_DeleteConsumerGroupOffsets_t*
588
- attach_function :rd_kafka_DeleteConsumerGroupOffsets_destroy, [:pointer], :void, blocking: true
589
- attach_function :rd_kafka_event_DeleteConsumerGroupOffsets_result, [:pointer], :pointer, blocking: true # rd_kafka_event_t* => rd_kafka_DeleteConsumerGroupOffsets_result_t*
590
- attach_function :rd_kafka_DeleteConsumerGroupOffsets_result_groups, [:pointer, :pointer], :pointer, blocking: true # rd_kafka_DeleteConsumerGroupOffsets_result_t*, size_t* => rd_kafka_group_result_t**
591
-
592
- # Delete Records
593
- RD_KAFKA_ADMIN_OP_DELETERECORDS = 6 # rd_kafka_admin_op_t
594
- RD_KAFKA_EVENT_DELETERECORDS_RESULT = 105 # rd_kafka_event_type_t
595
-
596
- attach_function :rd_kafka_DeleteRecords, [:pointer, :pointer, :size_t, :pointer, :pointer], :void, blocking: true
597
- attach_function :rd_kafka_DeleteRecords_new, [:pointer], :pointer, blocking: true
598
- attach_function :rd_kafka_DeleteRecords_destroy, [:pointer], :void, blocking: true
599
- attach_function :rd_kafka_event_DeleteRecords_result, [:pointer], :pointer, blocking: true # rd_kafka_event_t* => rd_kafka_DeleteRecords_result_t*
600
- attach_function :rd_kafka_DeleteRecords_result_offsets, [:pointer], :pointer, blocking: true # rd_kafka_DeleteRecords_result_t* => rd_kafka_topic_partition_list_t*
601
-
602
- # List Consumer Groups
603
- RD_KAFKA_ADMIN_OP_LISTCONSUMERGROUPS = 12 # rd_kafka_admin_op_t
604
- RD_KAFKA_EVENT_LISTCONSUMERGROUPS_RESULT = 0x2000 # rd_kafka_event_type_t
605
-
606
- # Consumer group states (rd_kafka_consumer_group_state_t)
607
- RD_KAFKA_CONSUMER_GROUP_STATE_UNKNOWN = 0
608
- RD_KAFKA_CONSUMER_GROUP_STATE_PREPARING_REBALANCE = 1
609
- RD_KAFKA_CONSUMER_GROUP_STATE_COMPLETING_REBALANCE = 2
610
- RD_KAFKA_CONSUMER_GROUP_STATE_STABLE = 3
611
- RD_KAFKA_CONSUMER_GROUP_STATE_DEAD = 4
612
- RD_KAFKA_CONSUMER_GROUP_STATE_EMPTY = 5
613
-
614
- attach_function :rd_kafka_ListConsumerGroups, [:pointer, :pointer, :pointer], :void, blocking: true
615
- attach_function :rd_kafka_event_ListConsumerGroups_result, [:pointer], :pointer, blocking: true # rd_kafka_event_t* => rd_kafka_ListConsumerGroups_result_t*
616
- attach_function :rd_kafka_ListConsumerGroups_result_valid, [:pointer, :pointer], :pointer, blocking: true # result*, size_t* => rd_kafka_ConsumerGroupListing_t**
617
- attach_function :rd_kafka_ListConsumerGroups_result_errors, [:pointer, :pointer], :pointer, blocking: true # result*, size_t* => rd_kafka_error_t**
618
- attach_function :rd_kafka_ConsumerGroupListing_group_id, [:pointer], :pointer, blocking: true # => const char*
619
- attach_function :rd_kafka_ConsumerGroupListing_is_simple_consumer_group, [:pointer], :int, blocking: true
620
- attach_function :rd_kafka_ConsumerGroupListing_state, [:pointer], :int, blocking: true
621
- attach_function :rd_kafka_consumer_group_state_name, [:int], :pointer, blocking: true # => const char*
622
-
623
- # Background Queue and Callback
624
-
625
- attach_function :rd_kafka_conf_set_background_event_cb, [:pointer, :pointer], :void
626
- attach_function :rd_kafka_queue_destroy, [:pointer], :void
627
-
628
- # Admin Options
629
-
630
- attach_function :rd_kafka_AdminOptions_new, [:pointer, :int32], :pointer
631
- attach_function :rd_kafka_AdminOptions_set_opaque, [:pointer, :pointer], :void
632
- attach_function :rd_kafka_AdminOptions_destroy, [:pointer], :void
633
-
634
- # Extracting data from event types
635
-
636
- attach_function :rd_kafka_event_type, [:pointer], :int32
637
- attach_function :rd_kafka_event_opaque, [:pointer], :pointer
638
- attach_function :rd_kafka_event_destroy, [:pointer], :void
639
-
640
- # Extracting data from topic results
641
-
642
- attach_function :rd_kafka_topic_result_error, [:pointer], :int32
643
- attach_function :rd_kafka_topic_result_error_string, [:pointer], :pointer
644
- attach_function :rd_kafka_topic_result_name, [:pointer], :pointer
645
-
646
- # Create Acls
647
- RD_KAFKA_ADMIN_OP_CREATEACLS = 9
648
- RD_KAFKA_EVENT_CREATEACLS_RESULT = 1024
649
-
650
- attach_function :rd_kafka_CreateAcls, [:pointer, :pointer, :size_t, :pointer, :pointer], :void
651
- attach_function :rd_kafka_event_CreateAcls_result, [:pointer], :pointer
652
- attach_function :rd_kafka_CreateAcls_result_acls, [:pointer, :pointer], :pointer
653
-
654
- # Delete Acls
655
- RD_KAFKA_ADMIN_OP_DELETEACLS = 11
656
- RD_KAFKA_EVENT_DELETEACLS_RESULT = 4096
657
-
658
- attach_function :rd_kafka_DeleteAcls, [:pointer, :pointer, :size_t, :pointer, :pointer], :void
659
- attach_function :rd_kafka_event_DeleteAcls_result, [:pointer], :pointer
660
- attach_function :rd_kafka_DeleteAcls_result_responses, [:pointer, :pointer], :pointer
661
- attach_function :rd_kafka_DeleteAcls_result_response_error, [:pointer], :pointer
662
- attach_function :rd_kafka_DeleteAcls_result_response_matching_acls, [:pointer, :pointer], :pointer
663
-
664
- # Describe Acls
665
- RD_KAFKA_ADMIN_OP_DESCRIBEACLS = 10
666
- RD_KAFKA_EVENT_DESCRIBEACLS_RESULT = 2048
667
-
668
- attach_function :rd_kafka_DescribeAcls, [:pointer, :pointer, :pointer, :pointer], :void
669
- attach_function :rd_kafka_event_DescribeAcls_result, [:pointer], :pointer
670
- attach_function :rd_kafka_DescribeAcls_result_acls, [:pointer, :pointer], :pointer
671
-
672
- # Acl Bindings
673
-
674
- attach_function :rd_kafka_AclBinding_restype, [:pointer], :int32
675
- attach_function :rd_kafka_AclBinding_name, [:pointer], :pointer
676
- attach_function :rd_kafka_AclBinding_resource_pattern_type, [:pointer], :int32
677
- attach_function :rd_kafka_AclBinding_principal, [:pointer], :pointer
678
- attach_function :rd_kafka_AclBinding_host, [:pointer], :pointer
679
- attach_function :rd_kafka_AclBinding_operation, [:pointer], :int32
680
- attach_function :rd_kafka_AclBinding_permission_type, [:pointer], :int32
681
- attach_function :rd_kafka_AclBinding_new, [:int32, :pointer, :int32, :pointer, :pointer, :int32, :int32, :pointer, :size_t], :pointer
682
- attach_function :rd_kafka_AclBindingFilter_new, [:int32, :pointer, :int32, :pointer, :pointer, :int32, :int32, :pointer, :size_t], :pointer
683
- attach_function :rd_kafka_AclBinding_destroy, [:pointer], :void
684
-
685
- # rd_kafka_ResourceType_t -
686
- # https://github.com/confluentinc/librdkafka/blob/292d2a66b992/src/rdkafka.h#L7307
687
- RD_KAFKA_RESOURCE_ANY = 1
688
- RD_KAFKA_RESOURCE_TOPIC = 2
689
- RD_KAFKA_RESOURCE_GROUP = 3
690
- RD_KAFKA_RESOURCE_BROKER = 4
691
- RD_KAFKA_RESOURCE_TRANSACTIONAL_ID = 5
692
-
693
- # rd_kafka_ResourcePatternType_t -
694
- # https://github.com/confluentinc/librdkafka/blob/292d2a66b992/src/rdkafka.h#L7320
695
- RD_KAFKA_RESOURCE_PATTERN_UNKNOWN = 0
696
- RD_KAFKA_RESOURCE_PATTERN_ANY = 1
697
- RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
698
- RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
699
- RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
700
-
701
- # rd_kafka_AclOperation_t -
702
- # https://github.com/confluentinc/librdkafka/blob/292d2a66b992/src/rdkafka.h#L8403
703
- RD_KAFKA_ACL_OPERATION_ANY = 1
704
- RD_KAFKA_ACL_OPERATION_ALL = 2
705
- RD_KAFKA_ACL_OPERATION_READ = 3
706
- RD_KAFKA_ACL_OPERATION_WRITE = 4
707
- RD_KAFKA_ACL_OPERATION_CREATE = 5
708
- RD_KAFKA_ACL_OPERATION_DELETE = 6
709
- RD_KAFKA_ACL_OPERATION_ALTER = 7
710
- RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
711
- RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
712
- RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
713
- RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
714
- RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
715
-
716
- # rd_kafka_AclPermissionType_t -
717
- # https://github.com/confluentinc/librdkafka/blob/292d2a66b992/src/rdkafka.h#L8435
718
- RD_KAFKA_ACL_PERMISSION_TYPE_ANY = 1
719
- RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
720
- RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
721
-
722
- # Extracting error details from Acl results
723
- attach_function :rd_kafka_acl_result_error, [:pointer], :pointer
724
- attach_function :rd_kafka_error_code, [:pointer], :int32
725
- attach_function :rd_kafka_error_string, [:pointer], :pointer
726
- attach_function :rd_kafka_event_error, [:pointer], :int32
727
- attach_function :rd_kafka_event_error_string, [:pointer], :pointer
728
- attach_function :rd_kafka_AclBinding_error, [:pointer], :pointer
729
-
730
- # FFI struct for native error (rd_kafka_error_t)
731
- class NativeError < FFI::Struct
732
- layout :code, :int32,
733
- :errstr, :pointer,
734
- :fatal, :u_int8_t,
735
- :retriable, :u_int8_t,
736
- :txn_requires_abort, :u_int8_t
737
- end
738
-
739
- attach_function :rd_kafka_group_result_error, [:pointer], NativeError.by_ref # rd_kafka_group_result_t* => rd_kafka_error_t*
740
- attach_function :rd_kafka_group_result_name, [:pointer], :pointer
741
- attach_function :rd_kafka_group_result_partitions, [:pointer], :pointer # rd_kafka_group_result_t* => rd_kafka_topic_partition_list_t*
742
87
  end
743
88
  end
89
+
90
+ require_relative "bindings/structs"
91
+ require_relative "bindings/polling"
92
+ require_relative "bindings/metadata"
93
+ require_relative "bindings/messages"
94
+ require_relative "bindings/errors"
95
+ require_relative "bindings/configuration"
96
+ require_relative "bindings/callbacks"
97
+ require_relative "bindings/handle"
98
+ require_relative "bindings/consumer"
99
+ require_relative "bindings/producer"
100
+ require_relative "bindings/admin"