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
data/README.md
CHANGED
|
@@ -1,51 +1,62 @@
|
|
|
1
1
|
# Rdkafka
|
|
2
2
|
|
|
3
|
-
[](https://github.com/karafka/rdkafka-ruby/actions/workflows/ci_linux_ubuntu_x86_64_gnu.yml)
|
|
4
4
|
[](https://badge.fury.io/rb/rdkafka)
|
|
5
|
-
[](https://slack.karafka.io)
|
|
6
|
+
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> The `rdkafka-ruby` gem was created and developed by [AppSignal](https://www.appsignal.com/). Their impactful contributions have significantly shaped the Ruby Kafka and Karafka ecosystems. For robust monitoring, we highly recommend AppSignal.
|
|
9
|
+
|
|
10
|
+
---
|
|
6
11
|
|
|
7
12
|
The `rdkafka` gem is a modern Kafka client library for Ruby based on
|
|
8
|
-
[librdkafka](https://github.com/
|
|
13
|
+
[librdkafka](https://github.com/confluentinc/librdkafka/).
|
|
9
14
|
It wraps the production-ready C client using the [ffi](https://github.com/ffi/ffi)
|
|
10
|
-
gem and targets Kafka 1.0+ and Ruby versions
|
|
11
|
-
active maintenance. We remove Ruby version from our CI builds
|
|
15
|
+
gem and targets Kafka 1.0+ and Ruby versions under security or
|
|
16
|
+
active maintenance. We remove a Ruby version from our CI builds when they
|
|
12
17
|
become EOL.
|
|
13
18
|
|
|
14
|
-
`rdkafka` was written because
|
|
15
|
-
Kafka that supports modern Kafka at [AppSignal](https://appsignal.com).
|
|
16
|
-
We run it in production on very high traffic systems.
|
|
19
|
+
`rdkafka` was written because of the need for a reliable Ruby client for Kafka that supports modern Kafka at [AppSignal](https://appsignal.com). AppSignal runs it in production on very high-traffic systems.
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
an older version of Kafka and/or need the legacy simple consumer we
|
|
20
|
-
suggest using the [Hermann](https://github.com/reiseburo/hermann) gem.
|
|
21
|
-
|
|
22
|
-
The most important pieces of a Kafka client are implemented. We're
|
|
23
|
-
working towards feature completeness, you can track that here:
|
|
24
|
-
https://github.com/appsignal/rdkafka-ruby/milestone/1
|
|
21
|
+
The most essential pieces of a Kafka client are implemented, and we aim to provide all relevant consumer, producer, and admin APIs.
|
|
25
22
|
|
|
26
23
|
## Table of content
|
|
27
24
|
|
|
25
|
+
- [Project Scope](#project-scope)
|
|
28
26
|
- [Installation](#installation)
|
|
29
27
|
- [Usage](#usage)
|
|
30
|
-
* [Consuming
|
|
31
|
-
* [Producing
|
|
32
|
-
- [Higher
|
|
33
|
-
* [Message
|
|
34
|
-
* [Message
|
|
28
|
+
* [Consuming Messages](#consuming-messages)
|
|
29
|
+
* [Producing Messages](#producing-messages)
|
|
30
|
+
- [Higher Level Libraries](#higher-level-libraries)
|
|
31
|
+
* [Message Processing Frameworks](#message-processing-frameworks)
|
|
32
|
+
* [Message Publishing Libraries](#message-publishing-libraries)
|
|
33
|
+
- [Forking](#forking)
|
|
35
34
|
- [Development](#development)
|
|
36
35
|
- [Example](#example)
|
|
36
|
+
- [Versions](#versions)
|
|
37
|
+
|
|
38
|
+
## Project Scope
|
|
39
|
+
|
|
40
|
+
While rdkafka-ruby aims to simplify the use of librdkafka in Ruby applications, it's important to understand the limitations of this library:
|
|
41
|
+
|
|
42
|
+
- **No Complex Producers/Consumers**: This library does not intend to offer complex producers or consumers. The aim is to stick closely to the functionalities provided by librdkafka itself.
|
|
43
|
+
|
|
44
|
+
- **Focus on librdkafka Capabilities**: Features that can be achieved directly in Ruby, without specific needs from librdkafka, are outside the scope of this library.
|
|
45
|
+
|
|
46
|
+
- **Existing High-Level Functionalities**: Certain high-level functionalities like producer metadata cache and simple consumer are already part of the library. Although they fall slightly outside the primary goal, they will remain part of the contract, given their existing usage.
|
|
37
47
|
|
|
38
48
|
|
|
39
49
|
## Installation
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
have any problems installing the gem please open an issue.
|
|
51
|
+
When installed, this gem downloads and compiles librdkafka. If you have any problems installing the gem, please open an issue.
|
|
43
52
|
|
|
44
53
|
## Usage
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
Please see the [documentation](https://karafka.io/docs/code/rdkafka-ruby/) for full details on how to use this gem. Below are two quick examples.
|
|
47
56
|
|
|
48
|
-
|
|
57
|
+
Unless you are seeking specific low-level capabilities, we **strongly** recommend using [Karafka](https://github.com/karafka/karafka) and [WaterDrop](https://github.com/karafka/waterdrop) when working with Kafka. These are higher-level libraries also maintained by us based on rdkafka-ruby.
|
|
58
|
+
|
|
59
|
+
### Consuming Messages
|
|
49
60
|
|
|
50
61
|
Subscribe to a topic and get messages. Kafka will automatically spread
|
|
51
62
|
the available partitions over consumers with the same group id.
|
|
@@ -63,11 +74,11 @@ consumer.each do |message|
|
|
|
63
74
|
end
|
|
64
75
|
```
|
|
65
76
|
|
|
66
|
-
### Producing
|
|
77
|
+
### Producing Messages
|
|
67
78
|
|
|
68
|
-
Produce
|
|
79
|
+
Produce several messages, put the delivery handles in an array, and
|
|
69
80
|
wait for them before exiting. This way the messages will be batched and
|
|
70
|
-
sent to Kafka
|
|
81
|
+
efficiently sent to Kafka.
|
|
71
82
|
|
|
72
83
|
```ruby
|
|
73
84
|
config = {:"bootstrap.servers" => "localhost:9092"}
|
|
@@ -86,45 +97,54 @@ end
|
|
|
86
97
|
delivery_handles.each(&:wait)
|
|
87
98
|
```
|
|
88
99
|
|
|
89
|
-
Note that creating a producer consumes some resources that will not be
|
|
90
|
-
released until it `#close` is explicitly called, so be sure to call
|
|
91
|
-
`Config#producer` only as necessary.
|
|
100
|
+
Note that creating a producer consumes some resources that will not be released until it `#close` is explicitly called, so be sure to call `Config#producer` only as necessary.
|
|
92
101
|
|
|
93
|
-
## Higher
|
|
102
|
+
## Higher Level Libraries
|
|
94
103
|
|
|
95
|
-
Currently, there are two actively developed frameworks based on rdkafka-ruby
|
|
104
|
+
Currently, there are two actively developed frameworks based on `rdkafka-ruby`, that provide higher-level API that can be used to work with Kafka messages and one library for publishing messages.
|
|
96
105
|
|
|
97
|
-
### Message
|
|
106
|
+
### Message Processing Frameworks
|
|
98
107
|
|
|
99
108
|
* [Karafka](https://github.com/karafka/karafka) - Ruby and Rails efficient Kafka processing framework.
|
|
100
109
|
* [Racecar](https://github.com/zendesk/racecar) - A simple framework for Kafka consumers in Ruby
|
|
101
110
|
|
|
102
|
-
### Message
|
|
111
|
+
### Message Publishing Libraries
|
|
103
112
|
|
|
104
113
|
* [WaterDrop](https://github.com/karafka/waterdrop) – Standalone Karafka library for producing Kafka messages.
|
|
105
114
|
|
|
115
|
+
## Forking
|
|
116
|
+
|
|
117
|
+
When working with `rdkafka-ruby`, it's essential to know that the underlying `librdkafka` library does not support fork-safe operations, even though it is thread-safe. Forking a process after initializing librdkafka clients can lead to unpredictable behavior due to inherited file descriptors and memory states. This limitation requires careful handling, especially in Ruby applications that rely on forking.
|
|
118
|
+
|
|
119
|
+
To address this, it's highly recommended to:
|
|
120
|
+
|
|
121
|
+
- Never initialize any `rdkafka-ruby` producers or consumers before forking to avoid state corruption.
|
|
122
|
+
- Before forking, always close any open producers or consumers if you've opened any.
|
|
123
|
+
- Use high-level libraries like [WaterDrop](https://github.com/karafka/waterdrop) and [Karafka](https://github.com/karafka/karafka/), which provide abstractions for handling librdkafka's intricacies.
|
|
124
|
+
|
|
106
125
|
## Development
|
|
107
126
|
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
Contributors are encouraged to focus on enhancements that align with the core goal of the library. We appreciate contributions but will likely not accept pull requests for features that:
|
|
128
|
+
|
|
129
|
+
- Implement functionalities that can achieved using standard Ruby capabilities without changes to the underlying rdkafka-ruby bindings.
|
|
130
|
+
- Deviate significantly from the primary aim of providing librdkafka bindings with Ruby-friendly interfaces.
|
|
131
|
+
|
|
132
|
+
A Docker Compose file is included to run Kafka. To run that:
|
|
110
133
|
|
|
111
134
|
```
|
|
112
135
|
docker-compose up
|
|
113
136
|
```
|
|
114
137
|
|
|
115
|
-
Run `bundle` and `cd ext && bundle exec rake && cd ..` to download and
|
|
116
|
-
compile `librdkafka`.
|
|
138
|
+
Run `bundle` and `cd ext && bundle exec rake && cd ..` to download and compile `librdkafka`.
|
|
117
139
|
|
|
118
|
-
You can then run `bundle exec rspec` to run the tests. To see rdkafka
|
|
119
|
-
debug output:
|
|
140
|
+
You can then run `bundle exec rspec` to run the tests. To see rdkafka debug output:
|
|
120
141
|
|
|
121
142
|
```
|
|
122
143
|
DEBUG_PRODUCER=true bundle exec rspec
|
|
123
144
|
DEBUG_CONSUMER=true bundle exec rspec
|
|
124
145
|
```
|
|
125
146
|
|
|
126
|
-
After running the tests you can bring the cluster down to start with a
|
|
127
|
-
clean slate:
|
|
147
|
+
After running the tests, you can bring the cluster down to start with a clean slate:
|
|
128
148
|
|
|
129
149
|
```
|
|
130
150
|
docker-compose down
|
|
@@ -132,9 +152,36 @@ docker-compose down
|
|
|
132
152
|
|
|
133
153
|
## Example
|
|
134
154
|
|
|
135
|
-
To see everything working run these in separate tabs:
|
|
155
|
+
To see everything working, run these in separate tabs:
|
|
136
156
|
|
|
137
157
|
```
|
|
138
158
|
bundle exec rake consume_messages
|
|
139
159
|
bundle exec rake produce_messages
|
|
140
160
|
```
|
|
161
|
+
|
|
162
|
+
## Versions
|
|
163
|
+
|
|
164
|
+
| rdkafka-ruby | librdkafka | patches |
|
|
165
|
+
|-|-|-|
|
|
166
|
+
| 0.31.x (2026-10-09) | 2.15.1 (2026-09-09) | yes |
|
|
167
|
+
| 0.30.x (2026-09-25) | 2.15.0 (2026-06-30) | yes |
|
|
168
|
+
| 0.29.x (2026-07-10) | 2.14.2 (2026-06-03) | yes |
|
|
169
|
+
| 0.28.x (2026-06-03) | 2.14.1 (2026-04-15) | yes |
|
|
170
|
+
| 0.27.x (2026-05-07) | 2.14.0 (2026-04-01) | yes |
|
|
171
|
+
| 0.26.x (2026-03-30) | 2.13.2 (2026-03-02) | yes |
|
|
172
|
+
| 0.25.x (2026-01-21) | 2.12.1 (2025-10-21) | yes |
|
|
173
|
+
| 0.24.x (2025-10-10) | 2.11.1 (2025-08-18) | yes |
|
|
174
|
+
| 0.23.x (2025-09-04) | 2.11.0 (2025-07-03) | yes |
|
|
175
|
+
| 0.22.x (2025-07-17) | 2.8.0 (2025-01-07) | yes |
|
|
176
|
+
| 0.21.x (2025-02-13) | 2.8.0 (2025-01-07) | yes |
|
|
177
|
+
| 0.20.0 (2025-01-07) | 2.6.1 (2024-11-18) | yes |
|
|
178
|
+
| 0.19.0 (2024-10-01) | 2.5.3 (2024-09-02) | yes |
|
|
179
|
+
| 0.18.0 (2024-09-02) | 2.5.0 (2024-07-10) | yes |
|
|
180
|
+
| 0.17.0 (2024-08-03) | 2.4.0 (2024-05-07) | no |
|
|
181
|
+
| 0.16.0 (2024-06-13) | 2.3.0 (2023-10-25) | no |
|
|
182
|
+
| 0.15.0 (2023-12-03) | 2.3.0 (2023-10-25) | no |
|
|
183
|
+
| 0.14.0 (2023-11-21) | 2.2.0 (2023-07-12) | no |
|
|
184
|
+
| 0.13.0 (2023-07-24) | 2.0.2 (2023-01-20) | no |
|
|
185
|
+
| 0.12.0 (2022-06-17) | 1.9.0 (2022-06-16) | no |
|
|
186
|
+
| 0.11.0 (2021-11-17) | 1.8.2 (2021-10-18) | no |
|
|
187
|
+
| 0.10.0 (2021-09-07) | 1.5.0 (2020-07-20) | no |
|
data/Rakefile
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
require 'bundler/gem_tasks'
|
|
3
|
+
require "bundler/gem_tasks"
|
|
6
4
|
require "./lib/rdkafka"
|
|
7
5
|
|
|
8
|
-
desc
|
|
6
|
+
desc "Generate some message traffic"
|
|
9
7
|
task :produce_messages do
|
|
10
|
-
config = {
|
|
8
|
+
config = { "bootstrap.servers": "localhost:9092" }
|
|
11
9
|
if ENV["DEBUG"]
|
|
12
10
|
config[:debug] = "broker,topic,msg"
|
|
13
11
|
end
|
|
@@ -17,24 +15,24 @@ task :produce_messages do
|
|
|
17
15
|
100.times do |i|
|
|
18
16
|
puts "Producing message #{i}"
|
|
19
17
|
delivery_handles << producer.produce(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
topic: "rake_test_topic",
|
|
19
|
+
payload: "Payload #{i} from Rake",
|
|
20
|
+
key: "Key #{i} from Rake"
|
|
23
21
|
)
|
|
24
22
|
end
|
|
25
|
-
puts
|
|
23
|
+
puts "Waiting for delivery"
|
|
26
24
|
delivery_handles.each(&:wait)
|
|
27
|
-
puts
|
|
25
|
+
puts "Done"
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
desc
|
|
28
|
+
desc "Consume some messages"
|
|
31
29
|
task :consume_messages do
|
|
32
30
|
config = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
"bootstrap.servers": "localhost:9092",
|
|
32
|
+
"group.id": "rake_test",
|
|
33
|
+
"enable.partition.eof": false,
|
|
34
|
+
"auto.offset.reset": "earliest",
|
|
35
|
+
"statistics.interval.ms": 10_000
|
|
38
36
|
}
|
|
39
37
|
if ENV["DEBUG"]
|
|
40
38
|
config[:debug] = "cgrp,topic,fetch"
|
|
@@ -42,7 +40,7 @@ task :consume_messages do
|
|
|
42
40
|
Rdkafka::Config.statistics_callback = lambda do |stats|
|
|
43
41
|
puts stats
|
|
44
42
|
end
|
|
45
|
-
|
|
43
|
+
Rdkafka::Config.new(config).consumer
|
|
46
44
|
consumer = Rdkafka::Config.new(config).consumer
|
|
47
45
|
consumer.subscribe("rake_test_topic")
|
|
48
46
|
consumer.each do |message|
|
|
@@ -50,14 +48,14 @@ task :consume_messages do
|
|
|
50
48
|
end
|
|
51
49
|
end
|
|
52
50
|
|
|
53
|
-
desc
|
|
51
|
+
desc "Hammer down"
|
|
54
52
|
task :load_test do
|
|
55
53
|
puts "Starting load test"
|
|
56
54
|
|
|
57
55
|
config = Rdkafka::Config.new(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
"bootstrap.servers": "localhost:9092",
|
|
57
|
+
"group.id": "load-test",
|
|
58
|
+
"enable.partition.eof": false
|
|
61
59
|
)
|
|
62
60
|
|
|
63
61
|
# Create a producer in a thread
|
|
@@ -67,9 +65,9 @@ task :load_test do
|
|
|
67
65
|
handles = []
|
|
68
66
|
1000.times do |i|
|
|
69
67
|
handles.push(producer.produce(
|
|
70
|
-
topic:
|
|
68
|
+
topic: "load_test_topic",
|
|
71
69
|
payload: "Payload #{i}",
|
|
72
|
-
key:
|
|
70
|
+
key: "Key #{i}"
|
|
73
71
|
))
|
|
74
72
|
end
|
|
75
73
|
handles.each(&:wait)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Checks Kafka logs for unsupported warning patterns
|
|
4
|
+
# Only specified warnings are allowed, all others should trigger failure
|
|
5
|
+
|
|
6
|
+
allowed_patterns=(
|
|
7
|
+
# Enabling share groups (KIP-932) requires "share" in group.coordinator.rebalance.protocols
|
|
8
|
+
# on cp-kafka 8.3.0 (Kafka 4.x). That mechanism is deprecated in favour of the share.version
|
|
9
|
+
# feature flag (Kafka 5.0), but is still functionally required to enable share groups in this
|
|
10
|
+
# version, so the broker logs this deprecation warning on every startup. Expected here.
|
|
11
|
+
"group.coordinator.rebalance.protocols. is deprecated"
|
|
12
|
+
"Performing controller activation"
|
|
13
|
+
"registered with feature metadata.version"
|
|
14
|
+
"Replayed TopicRecord for"
|
|
15
|
+
"Replayed PartitionRecord for"
|
|
16
|
+
"Previous leader None and previous leader epoch"
|
|
17
|
+
"Creating new"
|
|
18
|
+
"Unloaded transaction metadata"
|
|
19
|
+
"closing connection"
|
|
20
|
+
"sent a heartbeat request but received error REQUEST_TIMED_OUT"
|
|
21
|
+
"Topic '__consumer_offsets' already exists"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Get all warnings
|
|
25
|
+
warnings=$(docker logs --since=0 kafka | grep "] WARN ")
|
|
26
|
+
exit_code=0
|
|
27
|
+
|
|
28
|
+
while IFS= read -r line; do
|
|
29
|
+
allowed=0
|
|
30
|
+
for pattern in "${allowed_patterns[@]}"; do
|
|
31
|
+
if echo "$line" | grep -q "$pattern"; then
|
|
32
|
+
allowed=1
|
|
33
|
+
break
|
|
34
|
+
fi
|
|
35
|
+
done
|
|
36
|
+
|
|
37
|
+
if [ $allowed -eq 0 ]; then
|
|
38
|
+
echo "Unexpected warning found:"
|
|
39
|
+
echo "$line"
|
|
40
|
+
exit_code=1
|
|
41
|
+
fi
|
|
42
|
+
done <<< "$warnings"
|
|
43
|
+
|
|
44
|
+
exit $exit_code
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This patch is released under the 2-clause BSD license, same as librdkafka
|
|
2
|
+
#
|
|
3
|
+
--- librdkafka_2.5.3/src/rdkafka.h
|
|
4
|
+
+++ librdkafka_2.5.3/src/rdkafka.h
|
|
5
|
+
@@ -1101,6 +1101,10 @@ rd_kafka_topic_partition_t *rd_kafka_topic_partition_list_find(
|
|
6
|
+
const char *topic,
|
|
7
|
+
int32_t partition);
|
|
8
|
+
|
|
9
|
+
+/**
|
|
10
|
+
+ * @brief Allows for the global init of rdkafka when required in the Ruby process.
|
|
11
|
+
+ */
|
|
12
|
+
+RD_EXPORT void rd_kafka_global_init(void);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @brief Sort list using comparator \p cmp.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
services:
|
|
2
|
+
kafka:
|
|
3
|
+
container_name: kafka
|
|
4
|
+
image: confluentinc/cp-kafka:8.3.0
|
|
5
|
+
ports:
|
|
6
|
+
- 9092:9092 # Support PLAINTEXT so we can run one docker setup for SSL and PLAINTEXT
|
|
7
|
+
- 9093:9093
|
|
8
|
+
volumes:
|
|
9
|
+
- ./ssl:/etc/kafka/secrets
|
|
10
|
+
environment:
|
|
11
|
+
CLUSTER_ID: kafka-docker-cluster-1
|
|
12
|
+
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
|
13
|
+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
14
|
+
KAFKA_PROCESS_ROLES: broker,controller
|
|
15
|
+
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
|
|
16
|
+
KAFKA_LISTENERS: PLAINTEXT://:9092,SSL://:9093,CONTROLLER://:9094
|
|
17
|
+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL
|
|
18
|
+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093
|
|
19
|
+
KAFKA_BROKER_ID: 1
|
|
20
|
+
KAFKA_BROKER_RACK: rack-1
|
|
21
|
+
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9094
|
|
22
|
+
ALLOW_PLAINTEXT_LISTENER: 'yes'
|
|
23
|
+
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
|
|
24
|
+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
|
25
|
+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
|
26
|
+
KAFKA_GROUP_COORDINATOR_REBALANCE_PROTOCOLS: 'classic,consumer,share'
|
|
27
|
+
KAFKA_SHARE_COORDINATOR_STATE_TOPIC_REPLICATION_FACTOR: 1
|
|
28
|
+
KAFKA_SHARE_COORDINATOR_STATE_TOPIC_MIN_ISR: 1
|
|
29
|
+
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
|
|
30
|
+
KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
|
|
31
|
+
|
|
32
|
+
# SSL Configuration
|
|
33
|
+
KAFKA_SSL_KEYSTORE_FILENAME: kafka.server.keystore.jks
|
|
34
|
+
KAFKA_SSL_KEYSTORE_CREDENTIALS: kafka_keystore_creds
|
|
35
|
+
KAFKA_SSL_KEY_CREDENTIALS: kafka_ssl_key_creds
|
|
36
|
+
KAFKA_SSL_TRUSTSTORE_FILENAME: kafka.server.truststore.jks
|
|
37
|
+
KAFKA_SSL_TRUSTSTORE_CREDENTIALS: kafka_truststore_creds
|
|
38
|
+
KAFKA_SSL_CLIENT_AUTH: none
|
|
39
|
+
KAFKA_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: ""
|
data/docker-compose.yml
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
---
|
|
2
|
-
|
|
3
|
-
version: '2'
|
|
4
|
-
|
|
5
1
|
services:
|
|
6
|
-
zookeeper:
|
|
7
|
-
image: confluentinc/cp-zookeeper:5.2.6
|
|
8
|
-
environment:
|
|
9
|
-
ZOOKEEPER_CLIENT_PORT: 2181
|
|
10
|
-
ZOOKEEPER_TICK_TIME: 2000
|
|
11
|
-
|
|
12
2
|
kafka:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
container_name: kafka
|
|
4
|
+
image: confluentinc/cp-kafka:8.3.0
|
|
5
|
+
|
|
16
6
|
ports:
|
|
17
7
|
- 9092:9092
|
|
8
|
+
|
|
18
9
|
environment:
|
|
19
|
-
|
|
20
|
-
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
|
21
|
-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:9092
|
|
22
|
-
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
|
|
10
|
+
CLUSTER_ID: kafka-docker-cluster-1
|
|
23
11
|
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
|
24
12
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
13
|
+
KAFKA_PROCESS_ROLES: broker,controller
|
|
14
|
+
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
|
|
15
|
+
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
|
|
16
|
+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
|
|
17
|
+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092
|
|
18
|
+
KAFKA_BROKER_ID: 1
|
|
19
|
+
KAFKA_BROKER_RACK: rack-1
|
|
20
|
+
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@127.0.0.1:9093
|
|
21
|
+
ALLOW_PLAINTEXT_LISTENER: 'yes'
|
|
22
|
+
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
|
|
23
|
+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
|
24
|
+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
|
25
|
+
KAFKA_GROUP_COORDINATOR_REBALANCE_PROTOCOLS: 'classic,consumer,share'
|
|
26
|
+
KAFKA_SHARE_COORDINATOR_STATE_TOPIC_REPLICATION_FACTOR: 1
|
|
27
|
+
KAFKA_SHARE_COORDINATOR_STATE_TOPIC_MIN_ISR: 1
|
|
28
|
+
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
|
|
29
|
+
KAFKA_AUTHORIZER_CLASS_NAME: org.apache.kafka.metadata.authorizer.StandardAuthorizer
|
data/ext/Rakefile
CHANGED
|
@@ -1,40 +1,70 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require File.expand_path(
|
|
4
|
-
require "
|
|
3
|
+
require File.expand_path("../../lib/rdkafka/version", __FILE__)
|
|
4
|
+
require "digest"
|
|
5
5
|
require "fileutils"
|
|
6
6
|
require "open-uri"
|
|
7
7
|
|
|
8
|
-
task :
|
|
9
|
-
#
|
|
10
|
-
|
|
8
|
+
task default: :clean do
|
|
9
|
+
# For nix users, nix can't locate the file paths because the packages it's requiring aren't managed by the system but are
|
|
10
|
+
# managed by nix itself, so using the normal file paths doesn't work for nix users.
|
|
11
|
+
#
|
|
12
|
+
# Mini_portile causes an issue because it's dependencies are downloaded on the fly and therefore don't exist/aren't
|
|
13
|
+
# accessible in the nix environment
|
|
14
|
+
if ENV.fetch("RDKAFKA_EXT_PATH", "").empty?
|
|
15
|
+
# Download and compile librdkafka if RDKAFKA_EXT_PATH is not set
|
|
16
|
+
require "mini_portile2"
|
|
17
|
+
recipe = MiniPortile.new("librdkafka", Rdkafka::LIBRDKAFKA_VERSION)
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
# Use default homebrew openssl if we're on mac and the directory exists, is not using nix-prepared libraries
|
|
20
|
+
# and each of flags is not already set
|
|
21
|
+
if recipe.host&.include?("darwin") && system("which brew &> /dev/null") && Dir.exist?((homebrew_prefix = `brew --prefix openssl`.strip).to_s) && !ENV.key?("NIX_LDFLAGS")
|
|
22
|
+
ENV["CPPFLAGS"] = "-I#{homebrew_prefix}/include" unless ENV.key?("CPPFLAGS")
|
|
23
|
+
ENV["LDFLAGS"] = "-L#{homebrew_prefix}/lib" unless ENV.key?("LDFLAGS")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
releases = File.expand_path(File.join(File.dirname(__FILE__), "../dist"))
|
|
27
|
+
|
|
28
|
+
recipe.files << {
|
|
29
|
+
url: "file://#{releases}/librdkafka-#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz",
|
|
30
|
+
sha256: Rdkafka::LIBRDKAFKA_SOURCE_SHA256
|
|
31
|
+
}
|
|
32
|
+
recipe.configure_options = ["--host=#{recipe.host}"]
|
|
18
33
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
recipe.patch_files = Dir[File.join(releases, "patches", "*.patch")].sort
|
|
35
|
+
|
|
36
|
+
# Disable using libc regex engine in favor of the embedded one
|
|
37
|
+
# The default regex engine of librdkafka does not always work exactly as most of the users
|
|
38
|
+
# would expect, hence this flag allows for changing it to the other one
|
|
39
|
+
if ENV.key?("RDKAFKA_DISABLE_REGEX_EXT")
|
|
40
|
+
recipe.configure_options << "--disable-regex-ext"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
recipe.cook
|
|
44
|
+
# Move dynamic library we're interested in
|
|
45
|
+
if recipe.host.include?("darwin")
|
|
46
|
+
from_extension = "1.dylib"
|
|
47
|
+
to_extension = "dylib"
|
|
48
|
+
else
|
|
49
|
+
from_extension = "so.1"
|
|
50
|
+
to_extension = "so"
|
|
51
|
+
end
|
|
52
|
+
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
|
|
53
|
+
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
|
|
54
|
+
# Cleanup files created by miniportile we don't need in the gem
|
|
55
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
|
|
56
|
+
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
|
|
29
57
|
else
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
# Otherwise, copy existing libraries to ./ext
|
|
59
|
+
if ENV["RDKAFKA_EXT_PATH"].nil? || ENV["RDKAFKA_EXT_PATH"].empty?
|
|
60
|
+
raise "RDKAFKA_EXT_PATH must be set in your nix config when running under nix"
|
|
61
|
+
end
|
|
62
|
+
files = [
|
|
63
|
+
File.join(ENV["RDKAFKA_EXT_PATH"], "lib", "librdkafka.dylib"),
|
|
64
|
+
File.join(ENV["RDKAFKA_EXT_PATH"], "lib", "librdkafka.so")
|
|
65
|
+
]
|
|
66
|
+
files.each { |ext| FileUtils.cp(ext, File.dirname(__FILE__)) if File.exist?(ext) }
|
|
32
67
|
end
|
|
33
|
-
lib_path = File.join(File.dirname(__FILE__), "ports/#{recipe.host}/librdkafka/#{Rdkafka::LIBRDKAFKA_VERSION}/lib/librdkafka.#{from_extension}")
|
|
34
|
-
FileUtils.mv(lib_path, File.join(File.dirname(__FILE__), "librdkafka.#{to_extension}"))
|
|
35
|
-
# Cleanup files created by miniportile we don't need in the gem
|
|
36
|
-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
|
|
37
|
-
FileUtils.rm_rf File.join(File.dirname(__FILE__), "ports")
|
|
38
68
|
end
|
|
39
69
|
|
|
40
70
|
task :clean do
|
|
@@ -44,6 +74,42 @@ task :clean do
|
|
|
44
74
|
FileUtils.rm_rf File.join(File.dirname(__FILE__), "tmp")
|
|
45
75
|
end
|
|
46
76
|
|
|
77
|
+
namespace :dist do
|
|
78
|
+
task :dir do
|
|
79
|
+
ENV["RDKAFKA_DIST_PATH"] ||= File.expand_path(File.join(File.dirname(__FILE__), "..", "dist"))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
task file: "dist:dir" do
|
|
83
|
+
ENV["RDKAFKA_DIST_FILE"] ||= File.join(ENV["RDKAFKA_DIST_PATH"], "librdkafka_#{Rdkafka::LIBRDKAFKA_VERSION}.tar.gz")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
task clean: "dist:file" do
|
|
87
|
+
Dir.glob(File.join(ENV["RDKAFKA_DIST_PATH"].to_s, "*")).each do |filename|
|
|
88
|
+
next if filename.include? ENV["RDKAFKA_DIST_FILE"]
|
|
89
|
+
|
|
90
|
+
FileUtils.rm_rf filename
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
task download: "dist:file" do
|
|
95
|
+
version = Rdkafka::LIBRDKAFKA_VERSION
|
|
96
|
+
librdkafka_download = "https://codeload.github.com/confluentinc/librdkafka/tar.gz/v#{version}"
|
|
97
|
+
|
|
98
|
+
URI.open(librdkafka_download) do |file|
|
|
99
|
+
filename = ENV["RDKAFKA_DIST_FILE"]
|
|
100
|
+
data = file.read
|
|
101
|
+
|
|
102
|
+
if Digest::SHA256.hexdigest(data) != Rdkafka::LIBRDKAFKA_SOURCE_SHA256
|
|
103
|
+
raise "SHA256 does not match downloaded file"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
File.write(filename, data)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
task update: %w[dist:download dist:clean]
|
|
111
|
+
end
|
|
112
|
+
|
|
47
113
|
namespace :build do
|
|
48
114
|
desc "Build librdkafka at the given git sha or tag"
|
|
49
115
|
task :git, [:ref] do |task, args|
|
|
@@ -51,8 +117,9 @@ namespace :build do
|
|
|
51
117
|
version = "git-#{ref}"
|
|
52
118
|
|
|
53
119
|
recipe = MiniPortile.new("librdkafka", version)
|
|
54
|
-
recipe.files << "https://github.com/
|
|
55
|
-
recipe.configure_options = ["--host=#{recipe.host}","--enable-static", "--enable-zstd"]
|
|
120
|
+
recipe.files << "https://github.com/confluentinc/librdkafka/archive/#{ref}.tar.gz"
|
|
121
|
+
recipe.configure_options = ["--host=#{recipe.host}", "--enable-static", "--enable-zstd"]
|
|
122
|
+
recipe.patch_files = Dir[File.join(releases, "patches", "*.patch")].sort
|
|
56
123
|
recipe.cook
|
|
57
124
|
|
|
58
125
|
ext = recipe.host.include?("darwin") ? "dylib" : "so"
|