examples/mq/hashtable.rb in amqp-0.7.0.pre vs examples/mq/hashtable.rb in amqp-0.7.0
- old
+ new
@@ -1,23 +1,32 @@
+# encoding: utf-8
+
$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'
-AMQP.start(:host => 'localhost') do
+AMQP.start(:host => 'localhost') do |connection|
- def log *args
+ # Send Connection.Close on Ctrl+C
+ trap(:INT) do
+ unless connection.closing?
+ connection.close { exit! }
+ end
+ end
+
+ def log(*args)
p args
end
# AMQP.logging = true
class HashTable < Hash
- def get key
+ def get(key)
log 'HashTable', :get, key
self[key]
end
-
- def set key, value
+
+ def set(key, value)
log 'HashTable', :set, key => value
self[key] = value
end
def keys
@@ -35,18 +44,18 @@
end
client.set(:one, 1)
client.keys do |res|
log 'client', :keys => res
- AMQP.stop{ EM.stop }
+ AMQP.stop { EM.stop }
end
end
__END__
-["HashTable", :set, {:now=>Thu Jul 17 21:04:53 -0700 2008}]
+["HashTable", :set, {:now => Thu Jul 17 21:04:53 -0700 2008}]
["HashTable", :get, :now]
-["HashTable", :set, {:one=>1}]
+["HashTable", :set, {:one => 1}]
["HashTable", :keys]
-["client", {:eql?=>true, :now=>Thu Jul 17 21:04:53 -0700 2008}]
-["client", {:keys=>[:one, :now]}]
\ No newline at end of file
+["client", {:eql? => true, :now => Thu Jul 17 21:04:53 -0700 2008}]
+["client", {:keys => [:one, :now]}]