Sha256: d653887bcec478fab5f3c62f0cc83fa4cf99205be167ee429b01be68cd3766b0

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# encoding: utf-8

$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'

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 [ Time.now, *args ]
  end

  # AMQP.logging = true

  amq = MQ.new
  EM.add_periodic_timer(1) {
    puts

    log :sending, 'ping'
    amq.queue('one').publish('ping')
  }

  amq = MQ.new
  amq.queue('one').subscribe { |msg|
    log 'one', :received, msg, :sending, 'pong'
    amq.queue('two').publish('pong')
  }

  amq = MQ.new
  amq.queue('two').subscribe { |msg|
    log 'two', :received, msg
  }

end

__END__

[Sun Jul 20 03:52:24 -0700 2008, :sending, "ping"]
[Sun Jul 20 03:52:24 -0700 2008, "one", :received, "ping", :sending, "pong"]
[Sun Jul 20 03:52:24 -0700 2008, "two", :received, "pong"]

[Sun Jul 20 03:52:25 -0700 2008, :sending, "ping"]
[Sun Jul 20 03:52:25 -0700 2008, "one", :received, "ping", :sending, "pong"]
[Sun Jul 20 03:52:25 -0700 2008, "two", :received, "pong"]

[Sun Jul 20 03:52:26 -0700 2008, :sending, "ping"]
[Sun Jul 20 03:52:26 -0700 2008, "one", :received, "ping", :sending, "pong"]
[Sun Jul 20 03:52:26 -0700 2008, "two", :received, "pong"]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amqp-0.7.0 examples/mq/pingpong.rb