nsq-ruby 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nsq.rb +2 -0
- data/lib/nsq/client_base.rb +8 -2
- data/lib/nsq/connection.rb +2 -1
- data/lib/nsq/discovery.rb +25 -5
- data/lib/nsq/exceptions.rb +5 -0
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09966bb130fd77c7eb78c70c654afb4b2bd2246c
|
4
|
+
data.tar.gz: a900ade8f7497c4fcc738cd82900f90da7bb0172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7ce184b29b4eb00b46826a0ae3bbaa408cef197c89f6c074d4379c6e8e5623f38bcea1a587550c14734fdd19bb133f186ed910e85c5255c11d659ff70b4176
|
7
|
+
data.tar.gz: 2a0360c7b8b90e9099ae1e3dc1ad96de0ead23b3732ccafdc02e851fcab4af9a087c44f43f96d1d5d5ab34c2da45c086616bc17e19cb1bf3b5a1bbf029cdcb10
|
data/lib/nsq.rb
CHANGED
data/lib/nsq/client_base.rb
CHANGED
@@ -36,8 +36,14 @@ module Nsq
|
|
36
36
|
@discovery = Discovery.new(opts[:nsqlookupds])
|
37
37
|
|
38
38
|
loop do
|
39
|
-
|
40
|
-
|
39
|
+
begin
|
40
|
+
nsqds = nsqds_from_lookupd(opts[:topic])
|
41
|
+
drop_and_add_connections(nsqds)
|
42
|
+
rescue DiscoveryException
|
43
|
+
# We can't connect to any nsqlookupds. That's okay, we'll just
|
44
|
+
# leave our current nsqd connections alone and try again later.
|
45
|
+
warn 'Could not connect to any nsqlookupd instances in discovery loop'
|
46
|
+
end
|
41
47
|
sleep opts[:interval]
|
42
48
|
end
|
43
49
|
|
data/lib/nsq/connection.rb
CHANGED
@@ -393,7 +393,8 @@ module Nsq
|
|
393
393
|
def server_needs_rdy_re_ups?
|
394
394
|
# versions less than 0.3.0 need RDY re-ups
|
395
395
|
# see: https://github.com/bitly/nsq/blob/master/ChangeLog.md#030---2014-11-18
|
396
|
-
|
396
|
+
major, minor, patch = @server_version.split('.').map(&:to_i)
|
397
|
+
major == 0 && minor <= 2
|
397
398
|
end
|
398
399
|
|
399
400
|
|
data/lib/nsq/discovery.rb
CHANGED
@@ -21,10 +21,12 @@ module Nsq
|
|
21
21
|
# discovery.nsqds
|
22
22
|
# #=> ['127.0.0.1:4150', '127.0.0.1:4152']
|
23
23
|
#
|
24
|
+
# If all nsqlookupd's are unreachable, raises Nsq::DiscoveryException
|
25
|
+
#
|
24
26
|
def nsqds
|
25
|
-
|
27
|
+
gather_nsqds_from_all_lookupds do |lookupd|
|
26
28
|
get_nsqds(lookupd)
|
27
|
-
end
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
# Returns an array of nsqds instances that have messages for
|
@@ -35,14 +37,32 @@ module Nsq
|
|
35
37
|
# discovery.nsqds_for_topic('a-topic')
|
36
38
|
# #=> ['127.0.0.1:4150', '127.0.0.1:4152']
|
37
39
|
#
|
40
|
+
# If all nsqlookupd's are unreachable, raises Nsq::DiscoveryException
|
41
|
+
#
|
38
42
|
def nsqds_for_topic(topic)
|
39
|
-
|
43
|
+
gather_nsqds_from_all_lookupds do |lookupd|
|
40
44
|
get_nsqds(lookupd, topic)
|
41
|
-
end
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
48
|
+
|
44
49
|
private
|
45
50
|
|
51
|
+
def gather_nsqds_from_all_lookupds
|
52
|
+
nsqd_list = @lookupds.map do |lookupd|
|
53
|
+
yield(lookupd)
|
54
|
+
end.flatten
|
55
|
+
|
56
|
+
# All nsqlookupds were unreachable, raise an error!
|
57
|
+
if nsqd_list.length > 0 && nsqd_list.all? { |nsqd| nsqd.nil? }
|
58
|
+
raise DiscoveryException
|
59
|
+
end
|
60
|
+
|
61
|
+
nsqd_list.compact.uniq
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns an array of nsqd addresses
|
65
|
+
# If there's an error, return nil
|
46
66
|
def get_nsqds(lookupd, topic = nil)
|
47
67
|
uri_scheme = 'http://' unless lookupd.match(%r(https?://))
|
48
68
|
uri = URI.parse("#{uri_scheme}#{lookupd}")
|
@@ -68,7 +88,7 @@ module Nsq
|
|
68
88
|
end
|
69
89
|
rescue Exception => e
|
70
90
|
error "Error during discovery for #{lookupd}: #{e}"
|
71
|
-
|
91
|
+
nil
|
72
92
|
end
|
73
93
|
end
|
74
94
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsq-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wistia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/nsq/connection.rb
|
82
82
|
- lib/nsq/consumer.rb
|
83
83
|
- lib/nsq/discovery.rb
|
84
|
+
- lib/nsq/exceptions.rb
|
84
85
|
- lib/nsq/frames/error.rb
|
85
86
|
- lib/nsq/frames/frame.rb
|
86
87
|
- lib/nsq/frames/message.rb
|