Sha256: ebc5a0e0b42db87b2b5dd1bd88b1437dd0c7961774c0be44d46b502846f7f3b7
Contents?: true
Size: 1.79 KB
Versions: 4
Compression:
Stored size: 1.79 KB
Contents
$:.unshift File.dirname(__FILE__) + '/../lib' require 'mq' EM.run{ def log *args p [ Time.now, *args ] end # AMQP.logging = true EM.add_periodic_timer(1){ puts log :publishing, 'stock.usd.appl', price = 170+rand(1000)/100.0 MQ.topic.publish(price, :key => 'stock.usd.appl', :headers => {:symbol => 'appl'}) log :publishing, 'stock.usd.msft', price = 22+rand(500)/100.0 MQ.topic.publish(price, :key => 'stock.usd.msft', :headers => {:symbol => 'msft'}) } Thread.new{ amq = MQ.new amq.queue('apple stock').bind(amq.topic, :key => 'stock.usd.appl').subscribe{ |price| log 'apple stock', price } } Thread.new{ amq = MQ.new amq.queue('us stocks').bind(amq.topic, :key => 'stock.usd.*').subscribe{ |info, price| log 'us stock', info.headers[:symbol], price } } } __END__ [Thu Jul 17 14:51:07 -0700 2008, :publishing, "stock.usd.appl", 170.84] [Thu Jul 17 14:51:07 -0700 2008, :publishing, "stock.usd.msft", 23.68] [Thu Jul 17 14:51:07 -0700 2008, "apple stock", "170.84"] [Thu Jul 17 14:51:07 -0700 2008, "us stock", "appl", "170.84"] [Thu Jul 17 14:51:07 -0700 2008, "us stock", "msft", "23.68"] [Thu Jul 17 14:51:08 -0700 2008, :publishing, "stock.usd.appl", 173.61] [Thu Jul 17 14:51:08 -0700 2008, :publishing, "stock.usd.msft", 25.8] [Thu Jul 17 14:51:08 -0700 2008, "apple stock", "173.61"] [Thu Jul 17 14:51:08 -0700 2008, "us stock", "appl", "173.61"] [Thu Jul 17 14:51:08 -0700 2008, "us stock", "msft", "25.8"] [Thu Jul 17 14:51:09 -0700 2008, :publishing, "stock.usd.appl", 173.94] [Thu Jul 17 14:51:09 -0700 2008, :publishing, "stock.usd.msft", 24.88] [Thu Jul 17 14:51:09 -0700 2008, "apple stock", "173.94"] [Thu Jul 17 14:51:09 -0700 2008, "us stock", "appl", "173.94"] [Thu Jul 17 14:51:09 -0700 2008, "us stock", "msft", "24.88"]
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
tmm1-amqp-0.5.1 | examples/stocks.rb |
tmm1-amqp-0.5.2 | examples/stocks.rb |
amqp-0.5.1 | examples/stocks.rb |
amqp-0.5.2 | examples/stocks.rb |