Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor refactor

  • Loading branch information...
commit e9851516daab8cb2c212014d81eca3afdb99d15e 1 parent 0f382b3
Michael Klishin authored
View
12 lib/bunny/exchange.rb
@@ -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
@@ -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).
@@ -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
@@ -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
View
24 spec/higher_level_api/integration/predeclared_exchanges_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.