summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@lshift.net>2009-06-04 10:43:18 +0100
committerMatthew Sackman <matthew@lshift.net>2009-06-04 10:43:18 +0100
commitf34dc28de69bbf8c26c472914dbd0981bf32295f (patch)
tree316473c8ca111d4ab71fd1c1a182b8046f8f7ac3
parent04238dcb89b86cb6dcba155e99fa52bf8759f330 (diff)
parent08299fba892f017fc98ccb31c43a6fafc1583809 (diff)
downloadrabbitmq-server-f34dc28de69bbf8c26c472914dbd0981bf32295f.tar.gz
merge bug20633 into default
-rw-r--r--src/rabbit_exchange.erl40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index 0a7a9bc7..ca0e337b 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -386,32 +386,40 @@ call_with_exchange_and_queue(Exchange, Queue, Fun) ->
end).
add_binding(ExchangeName, QueueName, RoutingKey, Arguments) ->
- call_with_exchange_and_queue(
- ExchangeName, QueueName,
- fun (X, Q) ->
+ binding_action(
+ ExchangeName, QueueName, RoutingKey, Arguments,
+ fun (X, Q, B) ->
if Q#amqqueue.durable and not(X#exchange.durable) ->
{error, durability_settings_incompatible};
- true -> ok = sync_binding(
- ExchangeName, QueueName, RoutingKey, Arguments,
- Q#amqqueue.durable, fun mnesia:write/3)
+ true -> ok = sync_binding(B, Q#amqqueue.durable,
+ fun mnesia:write/3)
end
end).
delete_binding(ExchangeName, QueueName, RoutingKey, Arguments) ->
+ binding_action(
+ ExchangeName, QueueName, RoutingKey, Arguments,
+ fun (X, Q, B) ->
+ case mnesia:match_object(rabbit_route, #route{binding = B},
+ write) of
+ [] -> {error, binding_not_found};
+ _ -> ok = sync_binding(B, Q#amqqueue.durable,
+ fun mnesia:delete_object/3),
+ maybe_auto_delete(X)
+ end
+ end).
+
+binding_action(ExchangeName, QueueName, RoutingKey, Arguments, Fun) ->
call_with_exchange_and_queue(
ExchangeName, QueueName,
fun (X, Q) ->
- ok = sync_binding(
- ExchangeName, QueueName, RoutingKey, Arguments,
- Q#amqqueue.durable, fun mnesia:delete_object/3),
- maybe_auto_delete(X)
+ Fun(X, Q, #binding{exchange_name = ExchangeName,
+ queue_name = QueueName,
+ key = RoutingKey,
+ args = sort_arguments(Arguments)})
end).
-sync_binding(ExchangeName, QueueName, RoutingKey, Arguments, Durable, Fun) ->
- Binding = #binding{exchange_name = ExchangeName,
- queue_name = QueueName,
- key = RoutingKey,
- args = sort_arguments(Arguments)},
+sync_binding(Binding, Durable, Fun) ->
ok = case Durable of
true -> Fun(rabbit_durable_route,
#route{binding = Binding}, write);
@@ -477,7 +485,7 @@ parse_x_match(Other) ->
%% Horrendous matching algorithm. Depends for its merge-like
%% (linear-time) behaviour on the lists:keysort (sort_arguments) that
-%% route/3 and sync_binding/6 do.
+%% route/3 and {add,delete}_binding/4 do.
%%
%% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%% In other words: REQUIRES BOTH PATTERN AND DATA TO BE SORTED ASCENDING BY KEY.