rafka 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df959cd2ee8f851d10d7494c6beb7240384497b2
4
- data.tar.gz: dcd92cc278734b00628ec0d3233b9bf2bfed3793
3
+ metadata.gz: c5fe0a43fb774aaebab5f1b5d5a107aa6f0e3a6d
4
+ data.tar.gz: 53aab986230eccc406cae3d4a3cc5b1b16e7543e
5
5
  SHA512:
6
- metadata.gz: 4934b4ee1ac9da0d404f3f47647a3cb2f9e3526f3a6ab4a5c534b012bed5d525fee96646a5d87597b9f1fcaefb542990d88305c488670d3034ef0112b33d5901
7
- data.tar.gz: b631344f80573ffc66f1d17179b6403c75056303b2bcf9366c27821eb85dfd5a6f96e5cf631af1ce1acd313348f04324fe0696c1a01d0831e17eb240ec2816f4
6
+ metadata.gz: bdc9980b82e023297b15ee640001b15b45ee40b5de13aaf34f9668aa21deafbc50272dd22e03ed576f41b90f292b14f142a4d5f90be09014023e34fe4058de37
7
+ data.tar.gz: b10af1968c2541c0e198346d7a97d561de2e869363f15ce01526f08ec1bdf5543b7f29b6439586faef998e031e9f2107164c70bf028f8d6a9200fa0042c52aa6
@@ -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
 
@@ -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] :redis ({}) Configuration for the
28
- # underlying Redis client (see {REDIS_DEFAULTS})
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
- @topic = "topics:#{@rafka_opts[:topic]}"
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(@topic, timeout: timeout)
267
+ msg = @redis.blpop(@blpop_arg, timeout: timeout)
258
268
  end
259
269
  end
260
270
  rescue ConsumeError => e
@@ -1,3 +1,3 @@
1
1
  module Rafka
2
- VERSION = "0.2.5".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -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.2.5
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-05-14 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis