rafka 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rafka.rb +25 -1
- data/lib/rafka/consumer.rb +29 -7
- data/lib/rafka/version.rb +1 -1
- 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: 4b373f61cafd171166bb214fca2e36d3f7e36c40
|
4
|
+
data.tar.gz: 3baee498081c2aabfd195074cdb2695ad5b4711a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa3b522f9fc732d72be3aeba84c891223545651c41a8b61a4144ddbb0f5fcbac0673b8c17460358cb058cee21130df1f8819a70e3fb99c6e04461cb1ee2bcd7
|
7
|
+
data.tar.gz: 38c9e593ded9496547dbdf4b3445dbd7b622b3a232ae7c833fb7d0689dc9625b15b857f45e9c2d1ca246ed5a3086ee0cbfa46463794a9f61889cba9fd24de4d2
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ rafka-rb: Ruby driver for Rafka
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/rafka.svg)](https://badge.fury.io/rb/rafka-rb)
|
4
4
|
[![Documentation](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/skroutz/rafka-rb)
|
5
5
|
|
6
|
-
Rafka is a thin Ruby client library for [Rafka](https://github.com/skroutz/rafka
|
6
|
+
Rafka is a thin Ruby client library for [Rafka](https://github.com/skroutz/rafka),
|
7
7
|
providing a consumer and a producer with simple semantics. It is backed by
|
8
8
|
[redis-rb](https://github.com/redis/redis-rb).
|
9
9
|
|
data/lib/rafka.rb
CHANGED
@@ -12,7 +12,7 @@ module Rafka
|
|
12
12
|
DEFAULTS = {
|
13
13
|
host: "localhost",
|
14
14
|
port: 6380,
|
15
|
-
reconnect_attempts:
|
15
|
+
reconnect_attempts: 5,
|
16
16
|
}
|
17
17
|
|
18
18
|
def self.wrap_errors
|
@@ -27,5 +27,29 @@ module Rafka
|
|
27
27
|
raise CommandError, e.message
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
# redis-rb until 3.2.1 didn't retry to connect on
|
32
|
+
# Redis::CannotConnectError (eg. when rafka is down) so we manually retry
|
33
|
+
# 5 times
|
34
|
+
#
|
35
|
+
# TODO(agis): get rid of this method when we go to 3.2.1 or later, because
|
36
|
+
# https://github.com/redis/redis-rb/pull/476/
|
37
|
+
def self.with_retry(times: DEFAULTS[:reconnect_attempts], every_sec: 1)
|
38
|
+
attempts = 0
|
39
|
+
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
rescue Redis::CannotConnectError => e
|
43
|
+
if Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
|
44
|
+
if attempts < times
|
45
|
+
attempts += 1
|
46
|
+
sleep every_sec
|
47
|
+
retry
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
raise e
|
52
|
+
end
|
53
|
+
end
|
30
54
|
end
|
31
55
|
|
data/lib/rafka/consumer.rb
CHANGED
@@ -35,19 +35,41 @@ module Rafka
|
|
35
35
|
# @example
|
36
36
|
# consume(5) { |msg| puts "I received #{msg.value}" }
|
37
37
|
def consume(timeout=5)
|
38
|
-
#
|
38
|
+
# redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
|
39
|
+
# (https://github.com/redis/redis-rb/issues/510)
|
39
40
|
#
|
40
|
-
#
|
41
|
-
if !@connected && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
|
42
|
-
|
43
|
-
|
41
|
+
# TODO(agis): get rid of this when we drop support for 3.2.1 and before
|
42
|
+
if !@redis.client.connected? && Gem::Version.new(Redis::VERSION) < Gem::Version.new("3.2.2")
|
43
|
+
Rafka.wrap_errors do
|
44
|
+
@redis.client.call([:client, :setname, @redis.id])
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
48
|
raised = false
|
47
49
|
msg = nil
|
50
|
+
setname_attempts = 0
|
51
|
+
|
52
|
+
begin
|
53
|
+
Rafka.wrap_errors do
|
54
|
+
Rafka.with_retry do
|
55
|
+
msg = @redis.blpop(@topic, timeout: timeout)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rescue ConsumeError => e
|
59
|
+
# redis-rb didn't automatically call `CLIENT SETNAME` until v3.2.2
|
60
|
+
# (https://github.com/redis/redis-rb/issues/510)
|
61
|
+
#
|
62
|
+
# this is in case the server restarts while we were performing a BLPOP
|
63
|
+
#
|
64
|
+
# TODO(agis): get rid of this when we drop support for 3.2.1 and before
|
65
|
+
if e.message =~ /Identify yourself/ && setname_attempts < 5
|
66
|
+
sleep 0.5
|
67
|
+
@redis.client.call([:client, :setname, @redis.id])
|
68
|
+
setname_attempts += 1
|
69
|
+
retry
|
70
|
+
end
|
48
71
|
|
49
|
-
|
50
|
-
msg = @redis.blpop(@topic, timeout: timeout)
|
72
|
+
raise e
|
51
73
|
end
|
52
74
|
|
53
75
|
return if !msg
|
data/lib/rafka/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agis Anastasopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|