rafka 0.2.5 → 0.3.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 +16 -0
- data/README.md +8 -0
- data/lib/rafka/consumer.rb +15 -5
- data/lib/rafka/version.rb +1 -1
- data/test/consumer_test.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5fe0a43fb774aaebab5f1b5d5a107aa6f0e3a6d
|
4
|
+
data.tar.gz: 53aab986230eccc406cae3d4a3cc5b1b16e7543e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdc9980b82e023297b15ee640001b15b45ee40b5de13aaf34f9668aa21deafbc50272dd22e03ed576f41b90f292b14f142a4d5f90be09014023e34fe4058de37
|
7
|
+
data.tar.gz: b10af1968c2541c0e198346d7a97d561de2e869363f15ce01526f08ec1bdf5543b7f29b6439586faef998e031e9f2107164c70bf028f8d6a9200fa0042c52aa6
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,22 @@ Breaking changes are prefixed with a "[BREAKING]" label.
|
|
5
5
|
## master (unreleased)
|
6
6
|
|
7
7
|
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## 0.3.0 (2018-06-07)
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- Consumers can now set their own librdkafka configuration [[#8](https://github.com/skroutz/rafka-rb/pull/8)]
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
8
24
|
## 0.2.5 (2018-05-15)
|
9
25
|
|
10
26
|
### Changed
|
data/README.md
CHANGED
@@ -102,6 +102,14 @@ msg2 = consumer.consume
|
|
102
102
|
consumer.commit(msg1, msg2) # => true
|
103
103
|
```
|
104
104
|
|
105
|
+
Consumers may also set their own custom [librdkafka configuration](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md):
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
consumer = Rafka::Consumer.new(
|
109
|
+
topic: "greetings", group: "myapp", librdkafka: { "auto.offset.reset" => "earliest" }
|
110
|
+
)
|
111
|
+
```
|
112
|
+
|
105
113
|
Refer to the [Consumer API documentation](http://www.rubydoc.info/github/skroutz/rafka-rb/Rafka/Consumer)
|
106
114
|
for more information.
|
107
115
|
|
data/lib/rafka/consumer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "json"
|
1
2
|
require "securerandom"
|
2
3
|
|
3
4
|
module Rafka
|
@@ -14,6 +15,9 @@ module Rafka
|
|
14
15
|
# @return [Redis::Client] the underlying Redis client instance
|
15
16
|
attr_reader :redis
|
16
17
|
|
18
|
+
# @return [String] the argument passed to BLPOP
|
19
|
+
attr_reader :blpop_arg
|
20
|
+
|
17
21
|
# Initialize a new consumer.
|
18
22
|
#
|
19
23
|
# @param [Hash] opts
|
@@ -24,8 +28,12 @@ module Rafka
|
|
24
28
|
# @option opts [String] :id (random) Kafka consumer id
|
25
29
|
# @option opts [Boolean] :auto_commit (true) automatically commit
|
26
30
|
# offsets
|
27
|
-
# @option opts [Hash] :
|
28
|
-
#
|
31
|
+
# @option opts [Hash] :librdkafka ({}) librdkafka configuration. It will
|
32
|
+
# be merged over the existing configuration set in the server.
|
33
|
+
# See https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
|
34
|
+
# for more information
|
35
|
+
# @option opts [Hash] :redis ({}) Configuration for the underlying Redis
|
36
|
+
# client. See {REDIS_DEFAULTS}
|
29
37
|
#
|
30
38
|
# @raise [RuntimeError] if a required option was not provided
|
31
39
|
# (see {REQUIRED_OPTS})
|
@@ -35,10 +43,12 @@ module Rafka
|
|
35
43
|
opts[:id] ||= SecureRandom.hex
|
36
44
|
opts[:id] = "#{opts[:group]}:#{opts[:id]}"
|
37
45
|
opts[:auto_commit] = true if opts[:auto_commit].nil?
|
46
|
+
opts[:librdkafka] ||= {}
|
38
47
|
|
39
48
|
@rafka_opts, @redis_opts = parse_opts(opts)
|
40
49
|
@redis = Redis.new(@redis_opts)
|
41
|
-
@
|
50
|
+
@blpop_arg = "topics:#{@rafka_opts[:topic]}"
|
51
|
+
@blpop_arg << ":#{opts[:librdkafka].to_json}" if !opts[:librdkafka].empty?
|
42
52
|
end
|
43
53
|
|
44
54
|
# Consumes the next message.
|
@@ -208,7 +218,7 @@ module Rafka
|
|
208
218
|
raise "#{opt.inspect} option not provided" if opts[opt].nil?
|
209
219
|
end
|
210
220
|
|
211
|
-
rafka_opts = opts.reject { |k| k == :redis }
|
221
|
+
rafka_opts = opts.reject { |k| k == :redis || k == :librdkafka }
|
212
222
|
|
213
223
|
redis_opts = REDIS_DEFAULTS.dup.merge(opts[:redis] || {})
|
214
224
|
redis_opts.merge!(
|
@@ -254,7 +264,7 @@ module Rafka
|
|
254
264
|
begin
|
255
265
|
Rafka.wrap_errors do
|
256
266
|
Rafka.with_retry(times: @redis_opts[:reconnect_attempts]) do
|
257
|
-
msg = @redis.blpop(@
|
267
|
+
msg = @redis.blpop(@blpop_arg, timeout: timeout)
|
258
268
|
end
|
259
269
|
end
|
260
270
|
rescue ConsumeError => e
|
data/lib/rafka/version.rb
CHANGED
data/test/consumer_test.rb
CHANGED
@@ -54,4 +54,17 @@ class ConsumerTest < Minitest::Test
|
|
54
54
|
assert_kind_of Rafka::Message, msg
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
def test_blpop_arg
|
59
|
+
cons = Rafka::Consumer.new(
|
60
|
+
group: "foo", topic: "bar", librdkafka: { test1: 2, test2: "a", "foo.bar" => true }
|
61
|
+
)
|
62
|
+
assert_equal cons.blpop_arg, 'topics:bar:{"test1":2,"test2":"a","foo.bar":true}'
|
63
|
+
|
64
|
+
cons = Rafka::Consumer.new(group: "foo", topic: "bar", librdkafka: {})
|
65
|
+
assert_equal cons.blpop_arg, "topics:bar"
|
66
|
+
|
67
|
+
cons = Rafka::Consumer.new(group: "foo", topic: "bar")
|
68
|
+
assert_equal cons.blpop_arg, "topics:bar"
|
69
|
+
end
|
57
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rafka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agis Anastasopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|