Skip to content

Commit d244684

Browse files
author
Matthew Sackman
committed
merge bug20633 into default
2 parents 56a9d55 + cfd34b0 commit d244684

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/rabbit_exchange.erl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,32 +386,40 @@ call_with_exchange_and_queue(Exchange, Queue, Fun) ->
386386
end).
387387

388388
add_binding(ExchangeName, QueueName, RoutingKey, Arguments) ->
389-
call_with_exchange_and_queue(
390-
ExchangeName, QueueName,
391-
fun (X, Q) ->
389+
binding_action(
390+
ExchangeName, QueueName, RoutingKey, Arguments,
391+
fun (X, Q, B) ->
392392
if Q#amqqueue.durable and not(X#exchange.durable) ->
393393
{error, durability_settings_incompatible};
394-
true -> ok = sync_binding(
395-
ExchangeName, QueueName, RoutingKey, Arguments,
396-
Q#amqqueue.durable, fun mnesia:write/3)
394+
true -> ok = sync_binding(B, Q#amqqueue.durable,
395+
fun mnesia:write/3)
397396
end
398397
end).
399398

400399
delete_binding(ExchangeName, QueueName, RoutingKey, Arguments) ->
400+
binding_action(
401+
ExchangeName, QueueName, RoutingKey, Arguments,
402+
fun (X, Q, B) ->
403+
case mnesia:match_object(rabbit_route, #route{binding = B},
404+
write) of
405+
[] -> {error, binding_not_found};
406+
_ -> ok = sync_binding(B, Q#amqqueue.durable,
407+
fun mnesia:delete_object/3),
408+
maybe_auto_delete(X)
409+
end
410+
end).
411+
412+
binding_action(ExchangeName, QueueName, RoutingKey, Arguments, Fun) ->
401413
call_with_exchange_and_queue(
402414
ExchangeName, QueueName,
403415
fun (X, Q) ->
404-
ok = sync_binding(
405-
ExchangeName, QueueName, RoutingKey, Arguments,
406-
Q#amqqueue.durable, fun mnesia:delete_object/3),
407-
maybe_auto_delete(X)
416+
Fun(X, Q, #binding{exchange_name = ExchangeName,
417+
queue_name = QueueName,
418+
key = RoutingKey,
419+
args = sort_arguments(Arguments)})
408420
end).
409421

410-
sync_binding(ExchangeName, QueueName, RoutingKey, Arguments, Durable, Fun) ->
411-
Binding = #binding{exchange_name = ExchangeName,
412-
queue_name = QueueName,
413-
key = RoutingKey,
414-
args = sort_arguments(Arguments)},
422+
sync_binding(Binding, Durable, Fun) ->
415423
ok = case Durable of
416424
true -> Fun(rabbit_durable_route,
417425
#route{binding = Binding}, write);
@@ -477,7 +485,7 @@ parse_x_match(Other) ->
477485

478486
%% Horrendous matching algorithm. Depends for its merge-like
479487
%% (linear-time) behaviour on the lists:keysort (sort_arguments) that
480-
%% route/3 and sync_binding/6 do.
488+
%% route/3 and {add,delete}_binding/4 do.
481489
%%
482490
%% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
483491
%% In other words: REQUIRES BOTH PATTERN AND DATA TO BE SORTED ASCENDING BY KEY.

0 commit comments

Comments
 (0)