diff options
author | Ben Hood <0x6e6562@gmail.com> | 2008-09-30 00:14:41 +0100 |
---|---|---|
committer | Ben Hood <0x6e6562@gmail.com> | 2008-09-30 00:14:41 +0100 |
commit | ae1a99b89db8f2a9f053a807441aa0945544aec4 (patch) | |
tree | 72206e0b1a0ae10bd5d69642cd707de4c9b00e5b | |
parent | 3bddea39793922ed08cbf0c08c375671e8f59228 (diff) | |
download | rabbitmq-server-ae1a99b89db8f2a9f053a807441aa0945544aec4.tar.gz |
Fix for auto_delete exchanges
-rw-r--r-- | src/rabbit_exchange.erl | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 53abd5e7..8c1228cc 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -225,6 +225,15 @@ lookup_qpids(Queues) -> %% refactored to its own module, especially seeing as unbind will have %% to be implemented for 0.91 ? delete_bindings(QueueName) -> + % TODO: The head of this list *SHOULD* always be the default exchange + % what if somebody nukes it? + [_|Exchanges] = exchanges_for_queue(QueueName), + lists:foreach(fun (Name) -> + Exchange = #exchange{name = Name, auto_delete = true, + type = '_', durable = '_', + arguments = '_'}, + ok = mnesia:delete_object(Exchange) end, Exchanges), + % TODO: What about auto_delete on durable exchanges? Binding = #binding{exchange_name = '_', queue_name = QueueName, key = '_'}, @@ -232,6 +241,12 @@ delete_bindings(QueueName) -> ok = mnesia:delete_object(Route), ok = mnesia:delete_object(ReverseRoute), ok = mnesia:delete_object(durable_routes, Route, write). + +exchanges_for_queue(QueueName) -> + MatchHead = #route{binding = #binding{exchange_name = '$1', + queue_name = QueueName, + key = '_'}}, + mnesia:dirty_select(route, [{MatchHead, [], ['$1']}]). call_with_exchange_and_queue(Exchange, Queue, Fun) -> rabbit_misc:execute_mnesia_transaction( |