nsq-cluster 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -10
- data/lib/nsq-cluster.rb +7 -6
- data/lib/nsq-cluster/nsqadmin.rb +1 -1
- data/lib/nsq-cluster/nsqd.rb +6 -10
- data/lib/nsq-cluster/nsqlookupd.rb +3 -2
- data/lib/nsq-cluster/process_wrapper.rb +5 -3
- 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: 912e82c06fc1606ed7a0c6cfcef965b7c150db75
|
4
|
+
data.tar.gz: 73cbfdcfa92085899ade4fd397a3d12c4477d043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63c76b46b7f9d20c8e75e018f8514f5d5f713ea4d0467123a9c0cfa33ae76eaeb777d2529b5ea0fb59275c440fa323cc7c1c672fe80616804f8604731f5ae870
|
7
|
+
data.tar.gz: 9802793529d7d68b1814204e2d31213ba25c6a473e64a897e36d08aba79318960d1efeac63fb3c9dba8b9e234765ecaa50606db52548fffe987f5f422466a0fd
|
data/README.md
CHANGED
@@ -3,22 +3,17 @@
|
|
3
3
|
Easily start up a local NSQ cluster. This is great for testing.
|
4
4
|
|
5
5
|
```ruby
|
6
|
-
# Start a cluster of 3 nsqd's and 2 nsqlookupd's
|
6
|
+
# Start a cluster of 3 nsqd's and 2 nsqlookupd's.
|
7
|
+
# This will block execution until all components are fully up and running.
|
7
8
|
cluster = NsqCluster.new(nsqd_count: 3, nsqlookupd_count: 2)
|
8
9
|
|
9
|
-
#
|
10
|
-
cluster.block_until_running
|
11
|
-
|
12
|
-
# Stop the 3rd nsqd instance
|
10
|
+
# Stop the 3rd nsqd instance and wait for it to come down.
|
13
11
|
cluster.nsqd.last.stop
|
14
12
|
|
15
|
-
#
|
16
|
-
cluster.nsqd.last.block_until_stopped
|
17
|
-
|
18
|
-
# Start it back up again
|
13
|
+
# Start it back up again and wait for it to fully start.
|
19
14
|
cluster.nsqd.last.start
|
20
15
|
|
21
|
-
# Tear down the whole cluster
|
16
|
+
# Tear down the whole cluster.
|
22
17
|
cluster.destroy
|
23
18
|
```
|
24
19
|
|
data/lib/nsq-cluster.rb
CHANGED
@@ -38,7 +38,10 @@ class NsqCluster
|
|
38
38
|
|
39
39
|
begin
|
40
40
|
# start everything!
|
41
|
-
all_services.each
|
41
|
+
all_services.each{|d| d.start(async: true)}
|
42
|
+
|
43
|
+
# by default, block execution until everything is started
|
44
|
+
block_until_running unless opts[:async]
|
42
45
|
rescue Exception => ex
|
43
46
|
# if we hit an error, stop everything that we started
|
44
47
|
destroy
|
@@ -51,8 +54,7 @@ class NsqCluster
|
|
51
54
|
(0...count).map do |idx|
|
52
55
|
Nsqlookupd.new(
|
53
56
|
options.merge({
|
54
|
-
|
55
|
-
http_port: 4161 + idx * 2
|
57
|
+
id: idx
|
56
58
|
}),
|
57
59
|
@verbose
|
58
60
|
)
|
@@ -64,9 +66,8 @@ class NsqCluster
|
|
64
66
|
(0...count).map do |idx|
|
65
67
|
Nsqd.new(
|
66
68
|
options.merge({
|
67
|
-
|
68
|
-
|
69
|
-
nsqlookupd: @nsqlookupd,
|
69
|
+
id: idx,
|
70
|
+
nsqlookupd: @nsqlookupd
|
70
71
|
}),
|
71
72
|
@verbose
|
72
73
|
)
|
data/lib/nsq-cluster/nsqadmin.rb
CHANGED
data/lib/nsq-cluster/nsqd.rb
CHANGED
@@ -6,15 +6,16 @@ class Nsqd < ProcessWrapper
|
|
6
6
|
include HTTPWrapper
|
7
7
|
|
8
8
|
|
9
|
-
attr_reader :host, :tcp_port, :http_port
|
9
|
+
attr_reader :host, :tcp_port, :http_port, :id
|
10
10
|
|
11
11
|
|
12
12
|
def initialize(opts = {}, verbose = false)
|
13
13
|
super
|
14
14
|
|
15
|
+
@id = opts.delete(:id) || 0
|
15
16
|
@host = opts.delete(:host) || '127.0.0.1'
|
16
|
-
@tcp_port = opts.delete(:tcp_port) || 4150
|
17
|
-
@http_port = opts.delete(:http_port) || 4151
|
17
|
+
@tcp_port = opts.delete(:tcp_port) || (4150 + @id * 2)
|
18
|
+
@http_port = opts.delete(:http_port) || (4151 + @id * 2)
|
18
19
|
@lookupd = opts.delete(:nsqlookupd) || []
|
19
20
|
@broadcast_address = opts.delete(:broadcast_address) || @host
|
20
21
|
|
@@ -43,7 +44,7 @@ class Nsqd < ProcessWrapper
|
|
43
44
|
%Q(--tcp-address=#{@host}:#{@tcp_port}),
|
44
45
|
%Q(--http-address=#{@host}:#{@http_port}),
|
45
46
|
%Q(--data-path=#{data_path}),
|
46
|
-
%Q(--worker-id=#{
|
47
|
+
%Q(--worker-id=#{id}),
|
47
48
|
%Q(--broadcast-address=#{@broadcast_address})
|
48
49
|
]
|
49
50
|
|
@@ -55,14 +56,9 @@ class Nsqd < ProcessWrapper
|
|
55
56
|
end
|
56
57
|
|
57
58
|
|
58
|
-
def worker_id
|
59
|
-
@tcp_port
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
59
|
# find or create a temporary data directory for this instance
|
64
60
|
def data_path
|
65
|
-
"/tmp/nsqd-#{
|
61
|
+
"/tmp/nsqd-#{id}"
|
66
62
|
end
|
67
63
|
|
68
64
|
|
@@ -9,9 +9,10 @@ class Nsqlookupd < ProcessWrapper
|
|
9
9
|
def initialize(opts = {}, verbose = false)
|
10
10
|
super
|
11
11
|
|
12
|
+
@id = opts.delete(:id) || 0
|
12
13
|
@host = opts.delete(:host) || '127.0.0.1'
|
13
|
-
@tcp_port = opts.delete(:tcp_port) || 4160
|
14
|
-
@http_port = opts.delete(:http_port) || 4161
|
14
|
+
@tcp_port = opts.delete(:tcp_port) || (4160 + @id * 2)
|
15
|
+
@http_port = opts.delete(:http_port) || (4161 + @id * 2)
|
15
16
|
@broadcast_address = opts.delete(:broadcast_address) || @host
|
16
17
|
|
17
18
|
@extra_args = opts.map do |key, value|
|
@@ -8,22 +8,24 @@ class ProcessWrapper
|
|
8
8
|
end
|
9
9
|
|
10
10
|
|
11
|
-
def start
|
11
|
+
def start(opts = {})
|
12
12
|
raise "#{command} is already running" if running? || another_instance_is_running?
|
13
13
|
@pid = spawn(command, *args, [:out, :err] => output)
|
14
|
+
block_until_running unless opts[:async]
|
14
15
|
end
|
15
16
|
|
16
17
|
|
17
|
-
def stop
|
18
|
+
def stop(opts = {})
|
18
19
|
raise "#{command} is not running" unless running?
|
19
20
|
Process.kill('TERM', @pid)
|
20
21
|
Process.waitpid(@pid)
|
21
22
|
@pid = nil
|
23
|
+
block_until_stopped unless opts[:async]
|
22
24
|
end
|
23
25
|
|
24
26
|
|
25
27
|
def destroy
|
26
|
-
stop if running?
|
28
|
+
stop(async: true) if running?
|
27
29
|
end
|
28
30
|
|
29
31
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsq-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wistia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sys-proctable
|