Sha256: 25807d20548ee9e081e8d004f1bd6753f679aa547d6cd10422b2e2e114092be8

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

# -*- coding: utf-8 -*-
require "spec_helper"

describe "Exclusive server-named queue" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec

  default_timeout 2

  amqp_before do
    @channel   = AMQP::Channel.new
    @channel.should be_open

    @exchange = AMQP::Exchange.default(@channel)
  end



  it "can be used for temporary point-to-point communication" do
    @exchange.channel.should == @channel

    @channel.queue("", :exclusive => true) do |queue1|
      puts "First callback has fired"
      @channel.queue("", :exclusive => true) do |queue2|
        puts "Second callback has fired"
        request_timestamp = Time.now.to_i
        reply_timestamp   = nil

        queue1.subscribe do |header, body|
          header.timestamp.to_i.should == request_timestamp.to_i
          header.app_id.should == "Client"
          header.reply_to.should == queue2.name

          reply_timestamp = Time.now.to_i
          @exchange.publish(rand(1000), :routing_key => header.reply_to, :reply_to => queue1.name, :app_id => "Server", :timestamp => reply_timestamp)
        end

        queue2.subscribe do |header, body|
          header.timestamp.to_i.should == reply_timestamp.to_i
          header.app_id.should == "Server"
          header.reply_to.should == queue1.name
        end


        # publish the request
        @exchange.publish(rand(1000),
                          :routing_key => queue1.name,
                          :reply_to    => queue2.name,
                          :app_id      => "Client",
                          :timestamp   => request_timestamp,
                          :mandatory   => true,
                          :immediate   => true)

        done(0.2) {
          queue1.unsubscribe
          queue2.unsubscribe
        }
      end # do
    end # do
  end # it
end # describe

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
amqp-0.8.0.rc13 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc12 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc11 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc10 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc9 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc8 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc7 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc6 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc5 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc4 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc3 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc2 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.rc1 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.pre.beta1 spec/integration/reply_queue_communication_spec.rb
amqp-0.8.0.beta1 spec/integration/reply_queue_communication_spec.rb