Class: NsqCluster
- Inherits:
-
Object
- Object
- NsqCluster
- Defined in:
- lib/nsq-cluster.rb
Instance Attribute Summary collapse
-
#nsqadmin ⇒ Object
readonly
Returns the value of attribute nsqadmin.
-
#nsqd ⇒ Object
readonly
Returns the value of attribute nsqd.
-
#nsqlookupd ⇒ Object
readonly
Returns the value of attribute nsqlookupd.
Instance Method Summary collapse
- #create_nsqadmin ⇒ Object
- #create_nsqds(count, options) ⇒ Object
- #create_nsqlookupds(count) ⇒ Object
- #destroy ⇒ Object
-
#initialize(opts = {}) ⇒ NsqCluster
constructor
A new instance of NsqCluster.
-
#nsqlookupd_http_endpoints ⇒ Object
return an array of http endpoints.
Constructor Details
#initialize(opts = {}) ⇒ NsqCluster
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nsq-cluster.rb', line 22 def initialize(opts = {}) opts = { nsqlookupd_count: 0, nsqd_count: 0, nsqadmin: false, nsqd_options: {}, silent: true }.merge(opts) @silent = opts[:silent] @nsqlookupd = create_nsqlookupds(opts[:nsqlookupd_count]) @nsqd = create_nsqds(opts[:nsqd_count], opts[:nsqd_options]) @nsqadmin = create_nsqadmin if opts[:nsqadmin] # start everything! (@nsqlookupd + @nsqd + [@nsqadmin]).compact.each { |d| d.start } end |
Instance Attribute Details
#nsqadmin ⇒ Object (readonly)
Returns the value of attribute nsqadmin.
20 21 22 |
# File 'lib/nsq-cluster.rb', line 20 def nsqadmin @nsqadmin end |
#nsqd ⇒ Object (readonly)
Returns the value of attribute nsqd.
20 21 22 |
# File 'lib/nsq-cluster.rb', line 20 def nsqd @nsqd end |
#nsqlookupd ⇒ Object (readonly)
Returns the value of attribute nsqlookupd.
20 21 22 |
# File 'lib/nsq-cluster.rb', line 20 def nsqlookupd @nsqlookupd end |
Instance Method Details
#create_nsqadmin ⇒ Object
65 66 67 68 69 70 |
# File 'lib/nsq-cluster.rb', line 65 def create_nsqadmin Nsqadmin.new( nsqlookupd: @nsqlookupd, silent: @silent ) end |
#create_nsqds(count, options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nsq-cluster.rb', line 53 def create_nsqds(count, ) (0...count).map do |idx| Nsqd.new(.merge({ tcp_port: 4150 + idx * 2, http_port: 4151 + idx * 2, nsqlookupd: @nsqlookupd, silent: @silent })) end end |
#create_nsqlookupds(count) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/nsq-cluster.rb', line 42 def create_nsqlookupds(count) (0...count).map do |idx| Nsqlookupd.new( tcp_port: 4160 + idx * 2, http_port: 4161 + idx * 2, silent: @silent ) end end |
#destroy ⇒ Object
73 74 75 |
# File 'lib/nsq-cluster.rb', line 73 def destroy (@nsqd + @nsqlookupd).each { |d| d.destroy } end |
#nsqlookupd_http_endpoints ⇒ Object
return an array of http endpoints
79 80 81 |
# File 'lib/nsq-cluster.rb', line 79 def nsqlookupd_http_endpoints @nsqlookupd.map { |lookupd| "http://#{lookupd.host}:#{lookupd.http_port}" } end |