Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Klishin committed Jan 19, 2013
1 parent 0f382b3 commit e985151
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/bunny/exchange.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require "bunny/compatibility"

module Bunny
# Represents AMQP 0.9.1 exchanges.
#
# @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
# @see http://rubybunny.info/articles/extensions.html RabbitMQ Extensions guide
class Exchange

include Bunny::Compatibility
Expand Down Expand Up @@ -43,8 +47,8 @@ class Exchange
# tasks_queue = channel.queue("tasks")
# Bunny::Exchange.default(channel).publish("make clean", routing_key => "tasks")
#
# @see Exchange
# @see http://files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
# @see http://rubybunny.info/articles/exchanges.html Exchanges and Publishing guide
# @see http://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf AMQP 0.9.1 specification (Section 2.1.2.4)
# @note Do not confuse default exchange with amq.direct: amq.direct is a pre-defined direct
# exchange that doesn't have any special routing semantics.
# @return [Exchange] An instance that corresponds to the default exchange (of type direct).
Expand All @@ -66,7 +70,7 @@ def initialize(channel_or_connection, type, name, opts = {})
@auto_delete = @options[:auto_delete]
@arguments = @options[:arguments]

declare! unless opts[:no_declare] || (@name =~ /^amq\.(direct|fanout|topic|match|headers)/) || (@name == AMQ::Protocol::EMPTY_STRING)
declare! unless opts[:no_declare] || predeclared? || (@name == AMQ::Protocol::EMPTY_STRING)

@channel.register_exchange(self)
end
Expand All @@ -88,7 +92,7 @@ def arguments
end

def predeclared?
@name == AMQ::Protocol::EMPTY_STRING || (@name =~ /^amq\.(direct|fanout|topic|match|headers)/)
@name =~ /^amq\.(direct|fanout|topic|match|headers)/
end


Expand Down
24 changes: 24 additions & 0 deletions spec/higher_level_api/integration/predeclared_exchanges_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "spec_helper"

describe "amq.* exchanges" do
let(:connection) do
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
c.start
c
end

after :all do
connection.close if connection.open?
end

it "are predeclared" do
ch = connection.create_channel

["amq.fanout", "amq.direct", "amq.topic", "amq.match", "amq.headers"].each do |e|
x = ch.exchange(e)
x.should be_predeclared
end

ch.close
end
end

0 comments on commit e985151

Please sign in to comment.