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, options) ⇒ 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
Returns a new instance of NsqCluster.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nsq-cluster.rb', line 22 def initialize(opts = {}) opts = { nsqlookupd_count: 0, nsqdlookupd_options: {}, nsqd_count: 0, nsqadmin: false, nsqd_options: {}, silent: true }.merge(opts) @silent = opts[:silent] @nsqlookupd = create_nsqlookupds(opts[:nsqlookupd_count], opts[:nsqdlookupd_options]) @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
66 67 68 69 70 71 |
# File 'lib/nsq-cluster.rb', line 66 def create_nsqadmin Nsqadmin.new( nsqlookupd: @nsqlookupd, silent: @silent ) end |
#create_nsqds(count, options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nsq-cluster.rb', line 54 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, options) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/nsq-cluster.rb', line 43 def create_nsqlookupds(count, ) (0...count).map do |idx| Nsqlookupd.new(.merge({ tcp_port: 4160 + idx * 2, http_port: 4161 + idx * 2, silent: @silent })) end end |
#destroy ⇒ Object
74 75 76 |
# File 'lib/nsq-cluster.rb', line 74 def destroy (@nsqd + @nsqlookupd).each { |d| d.destroy } end |
#nsqlookupd_http_endpoints ⇒ Object
return an array of http endpoints
80 81 82 |
# File 'lib/nsq-cluster.rb', line 80 def nsqlookupd_http_endpoints @nsqlookupd.map { |lookupd| "http://#{lookupd.host}:#{lookupd.http_port}" } end |