rafka 0.3.0 → 0.4.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: c5fe0a43fb774aaebab5f1b5d5a107aa6f0e3a6d
4
- data.tar.gz: 53aab986230eccc406cae3d4a3cc5b1b16e7543e
3
+ metadata.gz: 28f4bb6a0680cce617d517bf528b575cbb389c25
4
+ data.tar.gz: 0a17d24c5183175436d58c8e35dad93f752ec91b
5
5
  SHA512:
6
- metadata.gz: bdc9980b82e023297b15ee640001b15b45ee40b5de13aaf34f9668aa21deafbc50272dd22e03ed576f41b90f292b14f142a4d5f90be09014023e34fe4058de37
7
- data.tar.gz: b10af1968c2541c0e198346d7a97d561de2e869363f15ce01526f08ec1bdf5543b7f29b6439586faef998e031e9f2107164c70bf028f8d6a9200fa0042c52aa6
6
+ metadata.gz: 3197247d5b810b717bb7038c04ad3fd39eb63b7319f48d41f8c5eaa73d30d632d23312c2b795bc122ff1626c6c80395810fb47042ebd238d542b47b2e1d47382
7
+ data.tar.gz: 6200c187acaf499eb24ccc66b29e7c3185efa5784a81a88c6d7a892854ed6245665d27ca5b9c50ccfe6ee13b53107724e7188a25c2b2a7dbf1962812b791a797
@@ -9,7 +9,17 @@ Breaking changes are prefixed with a "[BREAKING]" label.
9
9
 
10
10
 
11
11
 
12
- ## 0.3.0 (2018-06-07)
12
+ ## 0.4.0 (2018-09-04)
13
+
14
+ ### Changed
15
+
16
+ - [BREAKING] Depend on redis-rb 3.3.2 or later [[#15](https://github.com/skroutz/rafka-rb/pull/15)]
17
+ - [BREAKING] `reconnect_attempts` option now defaults to `1` (ie. no reconnects) [[#15](https://github.com/skroutz/rafka-rb/pull/15)]
18
+
19
+
20
+
21
+
22
+
13
23
 
14
24
  ### Added
15
25
 
@@ -11,8 +11,7 @@ require "rafka/producer"
11
11
  module Rafka
12
12
  REDIS_DEFAULTS = {
13
13
  host: "localhost",
14
- port: 6380,
15
- reconnect_attempts: 5
14
+ port: 6380
16
15
  }.freeze
17
16
 
18
17
  def self.wrap_errors
@@ -22,28 +21,4 @@ module Rafka
22
21
  raise ConsumeError, e.message[5..-1] if e.message.start_with?("CONS ")
23
22
  raise CommandError, e.message
24
23
  end
25
-
26
- # redis-rb until 3.2.1 didn't retry to connect on
27
- # Redis::CannotConnectError (eg. when rafka is down) so we manually retry
28
- # 5 times
29
- #
30
- # TODO(agis): get rid of this method when we go to 3.2.1 or later, because
31
- # https://github.com/redis/redis-rb/pull/476/
32
- def self.with_retry(times: REDIS_DEFAULTS[:reconnect_attempts], every_sec: 1)
33
- attempts = 0
34
-
35
- begin
36
- yield
37
- rescue Redis::CannotConnectError => e
38
- if Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
39
- if attempts < times
40
- attempts += 1
41
- sleep every_sec
42
- retry
43
- end
44
- end
45
-
46
- raise e
47
- end
48
- end
49
24
  end
@@ -77,14 +77,6 @@ module Rafka
77
77
  # @example Consume a message and commit offset if the block does not raise an exception
78
78
  # consumer.consume { |msg| puts "I received #{msg.value}" }
79
79
  def consume(timeout=5)
80
- # redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
81
- # (https://github.com/redis/redis-rb/issues/510)
82
- #
83
- # TODO(agis): get rid of this when we drop support for 3.2.1 and before
84
- if !@redis.client.connected? && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
85
- set_name!
86
- end
87
-
88
80
  raised = false
89
81
  msg = consume_one(timeout)
90
82
 
@@ -145,14 +137,6 @@ module Rafka
145
137
  raise ArgumentError, "one of batch_size or batching_max_sec must be greater than 0"
146
138
  end
147
139
 
148
- # redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
149
- # (https://github.com/redis/redis-rb/issues/510)
150
- #
151
- # TODO(agis): get rid of this when we drop support for 3.2.1 and before
152
- if !@redis.client.connected? && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
153
- set_name!
154
- end
155
-
156
140
  raised = false
157
141
  start_time = Time.now
158
142
  msgs = []
@@ -246,12 +230,6 @@ module Rafka
246
230
  tp
247
231
  end
248
232
 
249
- def set_name!
250
- Rafka.wrap_errors do
251
- @redis.client.call([:client, :setname, @redis.id])
252
- end
253
- end
254
-
255
233
  # @param timeout [Fixnum]
256
234
  #
257
235
  # @raise [MalformedMessageError]
@@ -259,29 +237,9 @@ module Rafka
259
237
  # @return [nil, Message]
260
238
  def consume_one(timeout)
261
239
  msg = nil
262
- setname_attempts = 0
263
240
 
264
- begin
265
- Rafka.wrap_errors do
266
- Rafka.with_retry(times: @redis_opts[:reconnect_attempts]) do
267
- msg = @redis.blpop(@blpop_arg, timeout: timeout)
268
- end
269
- end
270
- rescue ConsumeError => e
271
- # redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
272
- # (https://github.com/redis/redis-rb/issues/510)
273
- #
274
- # this is in case the server restarts while we were performing a BLPOP
275
- #
276
- # TODO(agis): get rid of this when we drop support for 3.2.1 and before
277
- if e.message =~ /Identify yourself/ && setname_attempts < 5
278
- sleep 0.5
279
- set_name!
280
- setname_attempts += 1
281
- retry
282
- end
283
-
284
- raise e
241
+ Rafka.wrap_errors do
242
+ msg = @redis.blpop(@blpop_arg, timeout: timeout)
285
243
  end
286
244
 
287
245
  msg = Message.new(msg) if msg
@@ -40,11 +40,9 @@ module Rafka
40
40
  # produce("greetings", "Hola", key: "abc")
41
41
  def produce(topic, msg, key: nil)
42
42
  Rafka.wrap_errors do
43
- Rafka.with_retry(times: @options[:reconnect_attempts]) do
44
- redis_key = "topics:#{topic}"
45
- redis_key << ":#{key}" if key
46
- @redis.rpushx(redis_key, msg.to_s)
47
- end
43
+ redis_key = "topics:#{topic}"
44
+ redis_key << ":#{key}" if key
45
+ @redis.rpushx(redis_key, msg.to_s)
48
46
  end
49
47
  end
50
48
 
@@ -1,3 +1,3 @@
1
1
  module Rafka
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -64,6 +64,9 @@ class ConsumerTest < Minitest::Test
64
64
  cons = Rafka::Consumer.new(group: "foo", topic: "bar", librdkafka: {})
65
65
  assert_equal cons.blpop_arg, "topics:bar"
66
66
 
67
+ cons = Rafka::Consumer.new(group: "foo", topic: "bar", librdkafka: nil)
68
+ assert_equal cons.blpop_arg, "topics:bar"
69
+
67
70
  cons = Rafka::Consumer.new(group: "foo", topic: "bar")
68
71
  assert_equal cons.blpop_arg, "topics:bar"
69
72
  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.3.0
4
+ version: 0.4.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-06-07 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.2
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.2
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: minitest
29
35
  requirement: !ruby/object:Gem::Requirement