Class: Isimud::TestClient::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/isimud/test_client.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Queue) initialize(name, listener)

Returns a new instance of Queue



9
10
11
12
13
# File 'lib/isimud/test_client.rb', line 9

def initialize(name, listener)
  @name         = name
  @listener     = listener
  @routing_keys = Set.new
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



7
8
9
# File 'lib/isimud/test_client.rb', line 7

def name
  @name
end

- (Object) routing_keys (readonly)

Returns the value of attribute routing_keys



7
8
9
# File 'lib/isimud/test_client.rb', line 7

def routing_keys
  @routing_keys
end

Instance Method Details

- (Object) bind(exchange, options = {})



15
16
17
18
# File 'lib/isimud/test_client.rb', line 15

def bind(exchange, options = {})
  key = options[:routing_key]
  @routing_keys << Regexp.new(key.gsub(/\./, "\\.").gsub(/\*/, ".*"))
end

- (Boolean) has_matching_key?(route)

Returns:

  • (Boolean)


20
21
22
# File 'lib/isimud/test_client.rb', line 20

def has_matching_key?(route)
  @routing_keys.any? { |k| route =~ k }
end

- (Object) publish(data)



24
25
26
27
28
29
30
31
# File 'lib/isimud/test_client.rb', line 24

def publish(data)
  begin
    @listener.call(data)
  rescue => e
    puts "TestClient: error delivering message: #{e.message}\n  #{e.backtrace.join("\n  ")}"
    @listener.exception_handler.try(:call, e)
  end
end