Permalink
Browse files

make it possible to send messages with focring a queue declaration

  • Loading branch information...
skaes committed Feb 15, 2011
1 parent fbaa851 commit 7ca9fd8efd6631a6ba62a7b068e92306be44517f
Showing with 13 additions and 7 deletions.
  1. +1 −1 beetle.gemspec
  2. +2 −2 lib/beetle/client.rb
  3. +9 −3 test/beetle/client_test.rb
  4. +1 −1 test/beetle/publisher_test.rb
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "beetle"
- s.version = "0.2.10"
+ s.version = "0.2.11"
s.required_rubygems_version = ">= 1.3.1"
s.authors = ["Stefan Kaes", "Pascal Friederich", "Ali Jelveh", "Sebastian Roebke"]
s.date = Time.now.strftime('%Y-%m-%d')
View
@@ -66,7 +66,7 @@ def initialize(config = Beetle.config)
def register_exchange(name, options={})
name = name.to_s
raise ConfigurationError.new("exchange #{name} already configured") if exchanges.include?(name)
- exchanges[name] = options.symbolize_keys.merge(:type => :topic, :durable => true)
+ exchanges[name] = options.symbolize_keys.merge(:type => :topic, :durable => true, :queues => [])
end
# register a durable, non passive, non auto_deleted queue with the given _name_ and an _options_ hash:
@@ -101,7 +101,7 @@ def register_binding(queue_name, options={})
key = (opts[:key] || name).to_s
(bindings[name] ||= []) << {:exchange => exchange, :key => key}
register_exchange(exchange) unless exchanges.include?(exchange)
- queues = (exchanges[exchange][:queues] ||= [])
+ queues = exchanges[exchange][:queues]
queues << name unless queues.include?(name)
end
View
@@ -40,7 +40,7 @@ def setup
test "registering an exchange should store it in the configuration with symbolized option keys and force a topic queue and durability" do
opts = {"durable" => false, "type" => "fanout"}
@client.register_exchange("some_exchange", opts)
- assert_equal({:durable => true, :type => :topic}, @client.exchanges["some_exchange"])
+ assert_equal({:durable => true, :type => :topic, :queues => []}, @client.exchanges["some_exchange"])
end
test "should convert exchange name to a string when registering an exchange" do
@@ -53,6 +53,12 @@ def setup
assert_raises(ConfigurationError){ @client.register_exchange("some_exchange") }
end
+ test "registering an exchange should initialize the list of queues bound to it" do
+ @client.register_exchange("some_exchange")
+ assert_equal [], @client.exchanges["some_exchange"][:queues]
+ assert_raises(ConfigurationError){ @client.register_exchange("some_exchange") }
+ end
+
test "registering a queue should automatically register the corresponding exchange if it doesn't exist yet" do
@client.register_queue("some_queue", "durable" => false, "exchange" => "some_exchange")
assert @client.exchanges.include?("some_exchange")
@@ -119,14 +125,14 @@ def setup
test "registering a message should register a corresponding exchange if it hasn't been registered yet" do
opts = { "exchange" => "some_exchange" }
@client.register_message("some_message", opts)
- assert_equal({:durable => true, :type => :topic}, @client.exchanges["some_exchange"])
+ assert_equal({:durable => true, :type => :topic, :queues => []}, @client.exchanges["some_exchange"])
end
test "registering a message should not fail if the exchange has already been registered" do
opts = { "exchange" => "some_exchange" }
@client.register_exchange("some_exchange")
@client.register_message("some_message", opts)
- assert_equal({:durable => true, :type => :topic}, @client.exchanges["some_exchange"])
+ assert_equal({:durable => true, :type => :topic, :queues => []}, @client.exchanges["some_exchange"])
end
test "should convert message name to a string when registering a message" do
@@ -290,7 +290,7 @@ def setup
test "accessing a given exchange should create it using the config. further access should return the created exchange" do
m = mock("Bunny")
- m.expects(:exchange).with("some_exchange", :type => :topic, :durable => true).returns(42)
+ m.expects(:exchange).with("some_exchange", :type => :topic, :durable => true, :queues => []).returns(42)
@client.register_exchange("some_exchange", :type => :topic, :durable => true)
@pub.expects(:bunny).returns(m)
ex = @pub.send(:exchange, "some_exchange")

0 comments on commit 7ca9fd8

Please sign in to comment.