examples/mq/multiclock.rb in amqp-0.7.0.pre vs examples/mq/multiclock.rb in amqp-0.7.0

- old
+ new

@@ -1,32 +1,41 @@ +# encoding: utf-8 + $:.unshift File.dirname(__FILE__) + '/../../lib' require 'mq' require 'time' -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 clock = MQ.new.headers('multiformat_clock') - EM.add_periodic_timer(1){ + EM.add_periodic_timer(1) { puts time = Time.new - ["iso8601","rfc2822"].each do |format| + ["iso8601", "rfc2822"].each do |format| formatted_time = time.send(format) log :publish, format, formatted_time clock.publish "#{formatted_time}", :headers => {"format" => format} end } - ["iso8601","rfc2822"].each do |format| + ["iso8601", "rfc2822"].each do |format| amq = MQ.new - amq.queue(format.to_s).bind(amq.headers('multiformat_clock'), :arguments => {"format" => format}).subscribe{ |time| + amq.queue(format.to_s).bind(amq.headers('multiformat_clock'), :arguments => {"format" => format}).subscribe { |time| log "received #{format}", time } end end @@ -44,6 +53,6 @@ ["received rfc2822", "Fri, 13 Feb 2009 19:55:41 -0800"] [:publish, "iso8601", "2009-02-13T19:55:42-08:00"] [:publish, "rfc2822", "Fri, 13 Feb 2009 19:55:42 -0800"] ["received iso8601", "2009-02-13T19:55:42-08:00"] -["received rfc2822", "Fri, 13 Feb 2009 19:55:42 -0800"] \ No newline at end of file +["received rfc2822", "Fri, 13 Feb 2009 19:55:42 -0800"]