class Nsqlookupd

Attributes

base_port[R]
host[R]
http_port[R]
tcp_port[R]

Public Class Methods

new(opts = {}, verbose = false) click to toggle source
Calls superclass method ProcessWrapper::new
# 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

Public Instance Methods

args() click to toggle source
# 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) click to toggle source

return a list of all known channels for a topic

# File lib/nsq-cluster/nsqlookupd.rb, line 56
def channels(topic)
  get 'channels', topic: topic
end
command() click to toggle source
# File lib/nsq-cluster/nsqlookupd.rb, line 29
def command
  'nsqlookupd'
end
delete(params = {}) click to toggle source

delete a topic or a channel in an existing topic

# File lib/nsq-cluster/nsqlookupd.rb, line 68
def delete(params = {})
  nsqlookupd_post 'delete', topic: params[:topic], channel: params[:channel]
end
info() click to toggle source

returns version number

# File lib/nsq-cluster/nsqlookupd.rb, line 80
def info
  get 'info'
end
lookup(topic) click to toggle source

return a list of producers for a topic

# File lib/nsq-cluster/nsqlookupd.rb, line 44
def lookup(topic)
  get 'lookup', topic: topic
end
nodes() click to toggle source

return a list of all known nsqd

# File lib/nsq-cluster/nsqlookupd.rb, line 62
def nodes
  get 'nodes'
end
ping() click to toggle source

monitoring endpoint

# File lib/nsq-cluster/nsqlookupd.rb, line 74
def ping
  get 'ping'
end
topics() click to toggle source

return a list of all known topics

# File lib/nsq-cluster/nsqlookupd.rb, line 50
def topics
  get 'topics'
end

Private Instance Methods

nsqlookupd_post(action, params) click to toggle source
# File lib/nsq-cluster/nsqlookupd.rb, line 88
def nsqlookupd_post(action, params)
  if params[:topic] && params[:channel]
    post "#{action}_channel", topic: params[:topic], channel: params[:channel]
  elsif params[:topic]
    post "#{action}_topic", topic: params[:topic]
  else
    raise 'you must specify a topic or topic and channel'
  end
end