Class: Krakow::Discovery

Inherits:
Object
  • Object
show all
Includes:
Utils::Lazy
Defined in:
lib/krakow/discovery.rb

Overview

Provides queue topic discovery

Attributes collapse

Instance Method Summary collapse

Methods included from Utils::Lazy

included

Methods included from Utils::Logging

level=, #log

Instance Method Details

#lookup(topic) ⇒ Array<Hash>

Get list of end points with given topic name available

Parameters:

  • topic (String)

    topic name

Returns:

  • (Array<Hash>)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/krakow/discovery.rb', line 28

def lookup(topic)
  result = [nsqlookupd].flatten.map do |location|
    uri = URI.parse(location)
    uri.path = '/lookup'
    uri.query = "topic=#{topic}&ts=#{Time.now.to_i}"
    begin
      debug "Requesting lookup for topic #{topic} - #{uri}"
      content = HTTP.with(:accept => 'application/octet-stream').get(uri.to_s)
      unless(content.respond_to?(:to_hash))
        data = MultiJson.load(content.to_s)
      else
        data = content.to_hash
      end
      debug "Lookup response (#{uri.to_s}): #{data.inspect}"
      if(data['data'] && data['data']['producers'])
        data['data']['producers'].map do |producer|
          Hash[*producer.map{|k,v| [k.to_sym, v]}.flatten]
        end
      end
    rescue => e
      warn "Lookup exception encountered: #{e.class.name} - #{e}"
      nil
    end
  end.compact.flatten(1).uniq
  debug "Discovery lookup result: #{result.inspect}"
  result
end

#nsqlookupd[Array, String]

Returns the nsqlookupd attribute.

Returns:

  • ([Array, String])

    the nsqlookupd attribute



20
# File 'lib/krakow/discovery.rb', line 20

attribute :nsqlookupd, [Array, String], :required => true

#nsqlookupd?TrueClass, FalseClass

Returns truthiness of the nsqlookupd attribute.

Returns:

  • (TrueClass, FalseClass)

    truthiness of the nsqlookupd attribute



20
# File 'lib/krakow/discovery.rb', line 20

attribute :nsqlookupd, [Array, String], :required => true