Sha256: 8fbda19f21ee286cf6badea7b3bfccb6a1990b10926e08b7f44ac2ef3c476ad8
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.3 | examples/mq/stocks.rb |
tmm1-amqp-0.5.5 | examples/mq/stocks.rb |
amqp-0.5.3 | examples/mq/stocks.rb |
amqp-0.5.5 | examples/mq/stocks.rb |