delivery_boy 0.2.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +18 -0
- data/README.md +28 -5
- data/delivery_boy.gemspec +2 -2
- data/lib/delivery_boy/config.rb +7 -0
- data/lib/delivery_boy/fake.rb +17 -5
- data/lib/delivery_boy/instance.rb +15 -2
- data/lib/delivery_boy/version.rb +1 -1
- data/lib/delivery_boy.rb +12 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12782da215edcc91544e184fd5804b2c21fb4a4be180f69addd0e2f7787884e
|
4
|
+
data.tar.gz: 6de9279ba3441524aceef6091a4feaf57d67a8623499779877b39ed9a11edad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6787bea888f6a2db4bb0d66eaad3c2234c9b6e4482c81ec69e43c27960b4c4a191ec553c0a24c87a46c5067811e2b9eb85265b34fc9457692465dfa8d902c5af
|
7
|
+
data.tar.gz: e10d3020dbaedfe5608fab51e6e1d343341919aab23b905766cdc386e2b844d5177d464fba93d69b79cc6d3704a5ad703ca97464f5754a363a9d362fecec2559
|
data/CHANGELOG
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v1.1.0
|
6
|
+
|
7
|
+
* Support for `ssl_client_cert_key_password` in the configuration (#52)
|
8
|
+
* Add `DeliveryBoy.buffer_size` to return the number of messages in the buffer
|
9
|
+
* Add `DeliveryBoy::Fake#clear_buffer` and `DeliveryBoy::Fake#buffer_size` to
|
10
|
+
support the public API when using the test helper.
|
11
|
+
* Support for `sasl_oauth_token_provider` in the configuration. (#55)
|
12
|
+
|
13
|
+
## v1.0.1
|
14
|
+
|
15
|
+
* Require ruby-kafka v1.0 or higher.
|
16
|
+
|
17
|
+
## v1.0.0
|
18
|
+
|
19
|
+
* Add `DeliveryBoy.clear_buffer` method.
|
20
|
+
* Support exactly once delivery and transactional messaging (#50)
|
21
|
+
* Check that Rails::Railtie is defined (#48)
|
22
|
+
|
5
23
|
## v0.2.8
|
6
24
|
|
7
25
|
* Support `log_level` config option.
|
data/README.md
CHANGED
@@ -66,7 +66,7 @@ A third method is to produce messages first (without delivering the messages to
|
|
66
66
|
class CommentsController < ApplicationController
|
67
67
|
def create
|
68
68
|
@comment = Comment.create!(params)
|
69
|
-
|
69
|
+
|
70
70
|
event = {
|
71
71
|
name: "comment_created",
|
72
72
|
data: {
|
@@ -74,13 +74,13 @@ A third method is to produce messages first (without delivering the messages to
|
|
74
74
|
user_id: current_user.id
|
75
75
|
}
|
76
76
|
}
|
77
|
-
|
77
|
+
|
78
78
|
# This will queue the two messages in the internal buffer.
|
79
79
|
DeliveryBoy.produce(comment.to_json, topic: "comments")
|
80
80
|
DeliveryBoy.produce(event.to_json, topic: "activity")
|
81
|
-
|
81
|
+
|
82
82
|
# This will deliver all messages in the buffer to Kafka.
|
83
|
-
# This call is blocking.
|
83
|
+
# This call is blocking.
|
84
84
|
DeliveryBoy.deliver_messages
|
85
85
|
end
|
86
86
|
end
|
@@ -220,11 +220,15 @@ A PEM encoded client cert to use with an SSL connection. Must be used in combina
|
|
220
220
|
|
221
221
|
A PEM encoded client cert key to use with an SSL connection. Must be used in combination with `ssl_client_cert`.
|
222
222
|
|
223
|
+
##### `ssl_client_cert_key_password`
|
224
|
+
|
225
|
+
The password required to read the ssl_client_cert_key. Must be used in combination with ssl_client_cert_key.
|
226
|
+
|
223
227
|
#### SASL Authentication and authorization
|
224
228
|
|
225
229
|
See [ruby-kafka](https://github.com/zendesk/ruby-kafka#authentication-using-sasl) for more information.
|
226
230
|
|
227
|
-
Use
|
231
|
+
Use it through `GSSAPI`, `PLAIN` _or_ `OAUTHBEARER`.
|
228
232
|
|
229
233
|
##### `sasl_gssapi_principal`
|
230
234
|
|
@@ -246,6 +250,25 @@ The username used to authenticate.
|
|
246
250
|
|
247
251
|
The password used to authenticate.
|
248
252
|
|
253
|
+
##### `sasl_oauth_token_provider`
|
254
|
+
|
255
|
+
A instance of a class which implements the `token` method.
|
256
|
+
As described in [ruby-kafka](https://github.com/zendesk/ruby-kafka/tree/c3e90bc355fad1e27b9af1048966ff08d3d5735b#oauthbearer)
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
class TokenProvider
|
260
|
+
def token
|
261
|
+
"oauth-token"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
DeliveryBoy.configure do |config|
|
266
|
+
config.sasl_oauth_token_provider = TokenProvider.new
|
267
|
+
config.ssl_ca_certs_from_system = true
|
268
|
+
end
|
269
|
+
```
|
270
|
+
|
271
|
+
|
249
272
|
### Testing
|
250
273
|
|
251
274
|
DeliveryBoy provides a test mode out of the box. When this mode is enabled, messages will be stored in memory rather than being sent to Kafka. If you use RSpec, enabling test mode is as easy as adding this to your spec helper:
|
data/delivery_boy.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "ruby-kafka", "~> 0
|
24
|
-
spec.add_runtime_dependency "king_konf", "~> 0
|
23
|
+
spec.add_runtime_dependency "ruby-kafka", "~> 1.0"
|
24
|
+
spec.add_runtime_dependency "king_konf", "~> 1.0"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/delivery_boy/config.rb
CHANGED
@@ -25,6 +25,9 @@ module DeliveryBoy
|
|
25
25
|
integer :max_retries, default: 2
|
26
26
|
integer :required_acks, default: -1
|
27
27
|
integer :retry_backoff, default: 1
|
28
|
+
boolean :idempotent, default: false
|
29
|
+
boolean :transactional, default: false
|
30
|
+
integer :transactional_timeout, default: 60
|
28
31
|
|
29
32
|
# Compression
|
30
33
|
integer :compression_threshold, default: 1
|
@@ -35,6 +38,7 @@ module DeliveryBoy
|
|
35
38
|
string :ssl_ca_cert_file_path
|
36
39
|
string :ssl_client_cert, default: nil
|
37
40
|
string :ssl_client_cert_key, default: nil
|
41
|
+
string :ssl_client_cert_key_password, default: nil
|
38
42
|
boolean :ssl_ca_certs_from_system, default: false
|
39
43
|
boolean :ssl_verify_hostname, default: true
|
40
44
|
|
@@ -49,6 +53,9 @@ module DeliveryBoy
|
|
49
53
|
string :sasl_scram_mechanism
|
50
54
|
boolean :sasl_over_ssl, default: true
|
51
55
|
|
56
|
+
# SASL OAUTHBEARER
|
57
|
+
attr_accessor :sasl_oauth_token_provider
|
58
|
+
|
52
59
|
# Datadog monitoring
|
53
60
|
boolean :datadog_enabled
|
54
61
|
string :datadog_host
|
data/lib/delivery_boy/fake.rb
CHANGED
@@ -2,7 +2,7 @@ module DeliveryBoy
|
|
2
2
|
|
3
3
|
# A fake implementation that is useful for testing.
|
4
4
|
class Fake
|
5
|
-
FakeMessage = Struct.new(:value, :topic, :key, :offset, :partition, :partition_key, :create_time) do
|
5
|
+
FakeMessage = Struct.new(:value, :topic, :key, :headers, :offset, :partition, :partition_key, :create_time) do
|
6
6
|
def bytesize
|
7
7
|
key.to_s.bytesize + value.to_s.bytesize
|
8
8
|
end
|
@@ -14,10 +14,10 @@ module DeliveryBoy
|
|
14
14
|
@delivery_lock = Mutex.new
|
15
15
|
end
|
16
16
|
|
17
|
-
def deliver(value, topic:, key: nil, partition: nil, partition_key: nil, create_time: Time.now)
|
17
|
+
def deliver(value, topic:, key: nil, headers: {}, partition: nil, partition_key: nil, create_time: Time.now)
|
18
18
|
@delivery_lock.synchronize do
|
19
19
|
offset = @messages[topic].count
|
20
|
-
message = FakeMessage.new(value, topic, key, offset, partition, partition_key, create_time)
|
20
|
+
message = FakeMessage.new(value, topic, key, headers, offset, partition, partition_key, create_time)
|
21
21
|
|
22
22
|
@messages[topic] << message
|
23
23
|
end
|
@@ -27,10 +27,10 @@ module DeliveryBoy
|
|
27
27
|
|
28
28
|
alias deliver_async! deliver
|
29
29
|
|
30
|
-
def produce(value, topic:, key: nil, partition: nil, partition_key: nil, create_time: Time.now)
|
30
|
+
def produce(value, topic:, key: nil, headers: {}, partition: nil, partition_key: nil, create_time: Time.now)
|
31
31
|
@delivery_lock.synchronize do
|
32
32
|
offset = @buffer[topic].count
|
33
|
-
message = FakeMessage.new(value, topic, key, offset, partition, partition_key, create_time)
|
33
|
+
message = FakeMessage.new(value, topic, key, headers, offset, partition, partition_key, create_time)
|
34
34
|
|
35
35
|
@buffer[topic] << message
|
36
36
|
end
|
@@ -51,6 +51,18 @@ module DeliveryBoy
|
|
51
51
|
clear
|
52
52
|
end
|
53
53
|
|
54
|
+
def clear_buffer
|
55
|
+
@delivery_lock.synchronize do
|
56
|
+
@buffer.clear
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def buffer_size
|
61
|
+
@delivery_lock.synchronize do
|
62
|
+
@buffer.values.flatten.size
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
54
66
|
# Clear all messages stored in memory.
|
55
67
|
def clear
|
56
68
|
@delivery_lock.synchronize do
|
@@ -14,7 +14,7 @@ module DeliveryBoy
|
|
14
14
|
sync_producer.deliver_messages
|
15
15
|
rescue
|
16
16
|
# Make sure to clear any buffered messages if there's an error.
|
17
|
-
|
17
|
+
clear_buffer
|
18
18
|
|
19
19
|
raise
|
20
20
|
end
|
@@ -36,6 +36,14 @@ module DeliveryBoy
|
|
36
36
|
sync_producer.deliver_messages
|
37
37
|
end
|
38
38
|
|
39
|
+
def clear_buffer
|
40
|
+
sync_producer.clear_buffer
|
41
|
+
end
|
42
|
+
|
43
|
+
def buffer_size
|
44
|
+
sync_producer.buffer_size
|
45
|
+
end
|
46
|
+
|
39
47
|
private
|
40
48
|
|
41
49
|
attr_reader :config, :logger
|
@@ -76,6 +84,7 @@ module DeliveryBoy
|
|
76
84
|
ssl_ca_cert_file_path: config.ssl_ca_cert_file_path,
|
77
85
|
ssl_client_cert: config.ssl_client_cert,
|
78
86
|
ssl_client_cert_key: config.ssl_client_cert_key,
|
87
|
+
ssl_client_cert_key_password: config.ssl_client_cert_key_password,
|
79
88
|
ssl_ca_certs_from_system: config.ssl_ca_certs_from_system,
|
80
89
|
ssl_verify_hostname: config.ssl_verify_hostname,
|
81
90
|
sasl_gssapi_principal: config.sasl_gssapi_principal,
|
@@ -86,7 +95,8 @@ module DeliveryBoy
|
|
86
95
|
sasl_scram_username: config.sasl_scram_username,
|
87
96
|
sasl_scram_password: config.sasl_scram_password,
|
88
97
|
sasl_scram_mechanism: config.sasl_scram_mechanism,
|
89
|
-
sasl_over_ssl: config.sasl_over_ssl
|
98
|
+
sasl_over_ssl: config.sasl_over_ssl,
|
99
|
+
sasl_oauth_token_provider: config.sasl_oauth_token_provider
|
90
100
|
)
|
91
101
|
end
|
92
102
|
|
@@ -101,6 +111,9 @@ module DeliveryBoy
|
|
101
111
|
max_buffer_bytesize: config.max_buffer_bytesize,
|
102
112
|
compression_codec: (config.compression_codec.to_sym if config.compression_codec),
|
103
113
|
compression_threshold: config.compression_threshold,
|
114
|
+
idempotent: config.idempotent,
|
115
|
+
transactional: config.transactional,
|
116
|
+
transactional_timeout: config.transactional_timeout,
|
104
117
|
}
|
105
118
|
end
|
106
119
|
end
|
data/lib/delivery_boy/version.rb
CHANGED
data/lib/delivery_boy.rb
CHANGED
@@ -4,7 +4,8 @@ require "delivery_boy/version"
|
|
4
4
|
require "delivery_boy/instance"
|
5
5
|
require "delivery_boy/fake"
|
6
6
|
require "delivery_boy/config"
|
7
|
-
require "delivery_boy/
|
7
|
+
require "delivery_boy/config_error"
|
8
|
+
require "delivery_boy/railtie" if defined?(Rails::Railtie)
|
8
9
|
|
9
10
|
module DeliveryBoy
|
10
11
|
class << self
|
@@ -80,6 +81,16 @@ module DeliveryBoy
|
|
80
81
|
instance.deliver_messages
|
81
82
|
end
|
82
83
|
|
84
|
+
# Clear any buffered messages generated by {.produce} or {.produce!} methods.
|
85
|
+
def clear_buffer
|
86
|
+
instance.clear_buffer
|
87
|
+
end
|
88
|
+
|
89
|
+
# Return the number of messages in the buffer
|
90
|
+
def buffer_size
|
91
|
+
instance.buffer_size
|
92
|
+
end
|
93
|
+
|
83
94
|
# Shut down DeliveryBoy.
|
84
95
|
#
|
85
96
|
# Automatically called when the process exits.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delivery_boy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-kafka
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: king_konf
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.2
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: A simple way to produce messages to Kafka from Ruby applications
|