Class: Nsqlookupd

Inherits:
ProcessWrapper show all
Includes:
HTTPWrapper
Defined in:
lib/nsq-cluster/nsqlookupd.rb

Constant Summary

Constants inherited from ProcessWrapper

ProcessWrapper::HTTPCHECK_INTERVAL

Instance Attribute Summary collapse

Attributes inherited from ProcessWrapper

#pid

Instance Method Summary collapse

Methods included from HTTPWrapper

#get, #post

Methods inherited from ProcessWrapper

#another_instance_is_running?, #block_until_running, #block_until_stopped, #destroy, #output, #running?, #start, #stop

Constructor Details

#initialize(opts = {}, verbose = false) ⇒ Nsqlookupd

Returns a new instance of Nsqlookupd.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nsq-cluster/nsqlookupd.rb', line 9

def initialize(opts = {}, verbose = false)
  super

  @id = opts.delete(:id) || 0
  @host = opts.delete(:host) || '127.0.0.1'

  # Use a non-standard nsqlookupd port by default so as to not conflict with
  # any local instances. This is helpful when running tests!
  @base_port = opts.delete(:base_port) || 4360

  @tcp_port = opts.delete(:tcp_port) || (@base_port + @id * 2)
  @http_port = opts.delete(:http_port) || (@base_port + 1 + @id * 2)
  @broadcast_address = opts.delete(:broadcast_address) || @host

  @extra_args = opts.map do |key, value|
    "--#{key.to_s.gsub('_', '-')}=#{value}"
  end
end

Instance Attribute Details

#base_portObject (readonly)

Returns the value of attribute base_port.



7
8
9
# File 'lib/nsq-cluster/nsqlookupd.rb', line 7

def base_port
  @base_port
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/nsq-cluster/nsqlookupd.rb', line 7

def host
  @host
end

#http_portObject (readonly)

Returns the value of attribute http_port.



7
8
9
# File 'lib/nsq-cluster/nsqlookupd.rb', line 7

def http_port
  @http_port
end

#tcp_portObject (readonly)

Returns the value of attribute tcp_port.



7
8
9
# File 'lib/nsq-cluster/nsqlookupd.rb', line 7

def tcp_port
  @tcp_port
end

Instance Method Details

#argsObject



34
35
36
37
38
39
40
# File 'lib/nsq-cluster/nsqlookupd.rb', line 34

def args
  [
    %Q(--tcp-address=#{@host}:#{@tcp_port}),
    %Q(--http-address=#{@host}:#{@http_port}),
    %Q(--broadcast-address=#{@broadcast_address})
  ] + @extra_args
end

#channels(topic) ⇒ Object

return a list of all known channels for a topic



56
57
58
# File 'lib/nsq-cluster/nsqlookupd.rb', line 56

def channels(topic)
  get 'channels', topic: topic
end

#commandObject



29
30
31
# File 'lib/nsq-cluster/nsqlookupd.rb', line 29

def command
  'nsqlookupd'
end

#delete(params = {}) ⇒ Object

delete a topic or a channel in an existing topic



68
69
70
# File 'lib/nsq-cluster/nsqlookupd.rb', line 68

def delete(params = {})
  nsqlookupd_post 'delete', topic: params[:topic], channel: params[:channel]
end

#infoObject

returns version number



80
81
82
# File 'lib/nsq-cluster/nsqlookupd.rb', line 80

def info
  get 'info'
end

#lookup(topic) ⇒ Object

return a list of producers for a topic



44
45
46
# File 'lib/nsq-cluster/nsqlookupd.rb', line 44

def lookup(topic)
  get 'lookup', topic: topic
end

#nodesObject

return a list of all known nsqd



62
63
64
# File 'lib/nsq-cluster/nsqlookupd.rb', line 62

def nodes
  get 'nodes'
end

#pingObject

monitoring endpoint



74
75
76
# File 'lib/nsq-cluster/nsqlookupd.rb', line 74

def ping
  get 'ping'
end

#topicsObject

return a list of all known topics



50
51
52
# File 'lib/nsq-cluster/nsqlookupd.rb', line 50

def topics
  get 'topics'
end