Sha256: a8070440c2ab4fc1cd1463bf4158c2fd6c68ee3bc9285ec26003c5b26d9cc0e8

Contents?: true

Size: 1.15 KB

Versions: 36

Compression:

Stored size: 1.15 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require "bundler"
Bundler.setup

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

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

  clock = AMQP::Channel.new.headers('multiformat_clock')
  EM.add_periodic_timer(1) {
    puts

    time = Time.new
    ["iso8601", "rfc2822"].each do |format|
      formatted_time = time.send(format)
      log :publish, format, formatted_time
      clock.publish "#{formatted_time}", :headers => {"format" => format} if connection.open?
    end
  }

  ["iso8601", "rfc2822"].each do |format|
    amq = AMQP::Channel.new
    amq.queue(format.to_s).bind(amq.headers('multiformat_clock'), :arguments => {"format" => format}).subscribe { |time|
      log "received #{format}", time
    }
  end

  show_stopper = Proc.new {
    connection.close do
      EM.stop
    end
  }

  Signal.trap "INT",  show_stopper
  Signal.trap "TERM", show_stopper

  EM.add_timer(3, show_stopper)

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
amqp-0.9.10 examples/legacy/multiclock.rb
amqp-0.9.9 examples/legacy/multiclock.rb
amqp-0.9.8 examples/legacy/multiclock.rb
amqp-0.9.7 examples/legacy/multiclock.rb
amqp-0.9.6 examples/legacy/multiclock.rb
amqp-0.9.5 examples/legacy/multiclock.rb
amqp-0.9.4 examples/legacy/multiclock.rb
amqp-0.9.3 examples/legacy/multiclock.rb
amqp-0.9.2 examples/legacy/multiclock.rb
amqp-0.9.1 examples/legacy/multiclock.rb
amqp-0.9.0 examples/legacy/multiclock.rb
amqp-0.9.0.pre3 examples/legacy/multiclock.rb
amqp-0.9.0.pre2 examples/legacy/multiclock.rb
amqp-0.9.0.pre1 examples/legacy/multiclock.rb
amqp-0.8.4 examples/legacy/multiclock.rb
amqp-0.8.3 examples/legacy/multiclock.rb
amqp-0.8.2 examples/legacy/multiclock.rb
amqp-0.8.1 examples/legacy/multiclock.rb
amqp-0.8.0 examples/legacy/multiclock.rb
amqp-0.8.0.rc15 examples/legacy/multiclock.rb