Class: Krakow::Discovery
- Inherits:
-
Object
- Object
- Krakow::Discovery
- Includes:
- Utils::Lazy
- Defined in:
- lib/krakow/discovery.rb
Overview
Provides queue topic discovery
Attributes (collapse)
-
- ([Array, String]) nsqlookupd
The nsqlookupd attribute.
-
- (TrueClass, FalseClass) nsqlookupd?
Truthiness of the nsqlookupd attribute.
Instance Method Summary (collapse)
-
- (Logger?) log(*args)
included
from Utils::Logging
Log message.
-
- (Array<Hash>) lookup(topic)
Get list of end points with given topic name available.
Instance Method Details
- (Logger?) log(*args) Originally defined in module Utils::Logging
Log message
- (Array<Hash>) lookup(topic)
Get list of end points with given topic name available
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 |
- ([Array, String]) nsqlookupd
Returns the nsqlookupd attribute
20 |
# File 'lib/krakow/discovery.rb', line 20 attribute :nsqlookupd, [Array, String], :required => true |
- (TrueClass, FalseClass) nsqlookupd?
Returns truthiness of the nsqlookupd attribute
20 |
# File 'lib/krakow/discovery.rb', line 20 attribute :nsqlookupd, [Array, String], :required => true |