Sha256: d264f8b3f02e729e044f4894786dae8bc300ab1f9f1435e81e526d1f9f1f901f

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8

$:.unshift(File.expand_path("../../lib", __FILE__))
require 'amqp'

AMQP.start(:host => 'localhost') do |connection|

  # 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)
      log 'HashTable', :get, key
      self[key]
    end

    def set(key, value)
      log 'HashTable', :set, key => value
      self[key] = value
    end

    def keys
      log 'HashTable', :keys
      super
    end
  end

  server = AMQP::Channel.new.rpc('hash table node', HashTable.new)

  client = AMQP::Channel.new.rpc('hash table node')
  client.set(:now, time = Time.now)
  client.get(:now) do |res|
    log 'client', :now => res, :eql? => res == time
  end

  client.set(:one, 1)
  client.keys do |res|
    log 'client', :keys => res
    AMQP.stop { EM.stop }
  end

end

__END__

["HashTable", :set, {:now => Thu Jul 17 21:04:53 -0700 2008}]
["HashTable", :get, :now]
["HashTable", :set, {:one => 1}]
["HashTable", :keys]
["client", {:eql? => true, :now => Thu Jul 17 21:04:53 -0700 2008}]
["client", {:keys => [:one, :now]}]

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
amqp-0.7.5 examples/hashtable.rb
amqp-0.7.4 examples/hashtable.rb
amqp-0.7.3 examples/hashtable.rb
amqp-0.7.2 examples/hashtable.rb
amqp-0.7.1 examples/hashtable.rb