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
# 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'
  @tcp_port = opts.delete(:tcp_port) || (4160 + @id * 2)
  @http_port = opts.delete(:http_port) || (4161 + @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

#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



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

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



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

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

#commandObject



24
25
26
# File 'lib/nsq-cluster/nsqlookupd.rb', line 24

def command
  'nsqlookupd'
end

#delete(params = {}) ⇒ Object

delete a topic or a channel in an existing topic



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

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

#infoObject

returns version number



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

def info
  get 'info'
end

#lookup(topic) ⇒ Object

return a list of producers for a topic



39
40
41
# File 'lib/nsq-cluster/nsqlookupd.rb', line 39

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

#nodesObject

return a list of all known nsqd



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

def nodes
  get 'nodes'
end

#pingObject

monitoring endpoint



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

def ping
  get 'ping'
end

#topicsObject

return a list of all known topics



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

def topics
  get 'topics'
end