examples/mq/clock.rb in amqp-0.6.7 vs examples/mq/clock.rb in amqp-0.7.0.pre
- old
+ new
@@ -1,33 +1,42 @@
$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'
-AMQP.start(:host => 'localhost') do
+AMQP.start(:host => 'localhost', port: 5673) do
def log *args
p args
end
# AMQP.logging = true
clock = MQ.new.fanout('clock')
+ clock2 = MQ.new.fanout('clock2')
+
EM.add_periodic_timer(1){
puts
log :publishing, time = Time.now
clock.publish(Marshal.dump(time))
}
+ EM.add_periodic_timer(1){
+ puts
+
+ log 2, :publishing, time = Time.now
+ clock.publish(Marshal.dump(time))
+ }
+
amq = MQ.new
- amq.queue('every second').bind(amq.fanout('clock')).subscribe{ |time|
+ q = amq.queue('every second')
+ q.bind(amq.fanout('clock')).subscribe{ |time|
log 'every second', :received, Marshal.load(time)
}
- amq = MQ.new
- amq.queue('every 5 seconds').bind(amq.fanout('clock')).subscribe{ |time|
- time = Marshal.load(time)
- log 'every 5 seconds', :received, time if time.strftime('%S').to_i%5 == 0
+ amq.queue!('every second').bind(amq.fanout('clock2')).subscribe{ |time|
+ log 2, 'every second', :received, Marshal.load(time)
}
+
end
__END__