Sha256: 3265cc0051b4f64a1f28da68a5df1020cf777c998c053834fddc4eef833c649b

Contents?: true

Size: 1.73 KB

Versions: 33

Compression:

Stored size: 1.73 KB

Contents

# encoding: 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)

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
amqp-1.8.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.7.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.6.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.5.3 spec/integration/reply_queue_communication_spec.rb
amqp-1.5.2 spec/integration/reply_queue_communication_spec.rb
amqp-1.5.1 spec/integration/reply_queue_communication_spec.rb
amqp-1.5.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.4.2 spec/integration/reply_queue_communication_spec.rb
amqp-1.4.1 spec/integration/reply_queue_communication_spec.rb
amqp-1.4.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.3.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.2.1 spec/integration/reply_queue_communication_spec.rb
amqp-1.2.0 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.8 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.7 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.6 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.5 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.4 spec/integration/reply_queue_communication_spec.rb
amqp-1.1.3 spec/integration/reply_queue_communication_spec.rb
amqp-1.0.4 spec/integration/reply_queue_communication_spec.rb