Permalink
Browse files

Allow exchanges to be declared as internal

While they cannot be used for publishing by clients, apps may still
need to bind them.
  • Loading branch information...
1 parent 43a9fc0 commit e238f573efeb484f735dc9ef3081a9ed2dd508e0 Michael Klishin committed Feb 4, 2014
Showing with 33 additions and 2 deletions.
  1. +2 −2 lib/bunny/channel.rb
  2. +8 −0 lib/bunny/exchange.rb
  3. +23 −0 spec/higher_level_api/integration/exchange_declare_spec.rb
View
@@ -1115,8 +1115,8 @@ def exchange_declare(name, type, opts = {})
opts.fetch(:passive, false),
opts.fetch(:durable, false),
opts.fetch(:auto_delete, false),
- false,
- false,
+ opts.fetch(:internal, false),
+ false, # nowait
opts[:arguments]))
Bunny::Timeout.timeout(read_write_timeout, ClientTimeout) do
@last_exchange_declare_ok = wait_on_continuations
View
@@ -85,6 +85,7 @@ def initialize(channel_or_connection, type, name, opts = {})
@durable = @options[:durable]
@auto_delete = @options[:auto_delete]
+ @internal = @options[:internal]
@arguments = @options[:arguments]
declare! unless opts[:no_declare] || predeclared? || (@name == AMQ::Protocol::EMPTY_STRING)
@@ -104,6 +105,12 @@ def auto_delete?
@auto_delete
end # auto_delete?
+ # @return [Boolean] true if this exchange is internal (used solely for exchange-to-exchange
+ # bindings and cannot be published to by clients)
+ def internal?
+ @internal
+ end
+
# @return [Hash] Additional optional arguments (typically used by RabbitMQ extensions and plugins)
# @api public
def arguments
@@ -261,6 +268,7 @@ def self.add_default_options(name, opts)
:passive => false,
:durable => false,
:auto_delete => false,
+ :internal => false,
:arguments => nil
}.merge(h)
else
@@ -201,4 +201,27 @@
end
end
end
+
+
+ context "that is internal" do
+ it "can be declared" do
+ ch = connection.create_channel
+ x = ch.fanout("bunny.tests.exchanges.internal", :internal => true)
+ x.should be_internal
+ x.delete
+
+ ch.close
+ end
+ end
+
+ context "not declared as internal" do
+ it "is not internal" do
+ ch = connection.create_channel
+ x = ch.fanout("bunny.tests.exchanges.non-internal")
+ x.should_not be_internal
+ x.delete
+
+ ch.close
+ end
+ end
end

0 comments on commit e238f57

Please sign in to comment.