diff options
| author | Ben Hood <0x6e6562@gmail.com> | 2008-08-05 01:15:19 +0100 |
|---|---|---|
| committer | Ben Hood <0x6e6562@gmail.com> | 2008-08-05 01:15:19 +0100 |
| commit | 8834453890e058115bdd53671029e34ffc0b0a08 (patch) | |
| tree | 3e142d3ddf2dbc8583c50b2752c52bdcd95b73d4 | |
| parent | dcfe7ed8ca7abcfa980b73a78e2f31d263d4e6de (diff) | |
| download | rabbitmq-server-git-8834453890e058115bdd53671029e34ffc0b0a08.tar.gz | |
Added vhost to binding spec
| -rw-r--r-- | include/rabbit.hrl | 10 | ||||
| -rw-r--r-- | src/rabbit_amqqueue.erl | 9 | ||||
| -rw-r--r-- | src/rabbit_exchange.erl | 30 |
3 files changed, 29 insertions, 20 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl index c40c4f2722..44268940e8 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -45,12 +45,12 @@ %% This constant field seems to be required because the underlying storage is %% ets, which stores key value pairs -%% The spec field is made up of an {Exchange, Binding, Queue} --record(forwards_binding, {spec, value = const}). -%% The spec field is made up of an {Queue, Binding, Exchange} --record(reverse_binding, {spec, value = const}). +%% The binding field is made up of an {Exchange, Binding, Queue} +-record(forwards_binding, {binding, value = const}). +%% The binding field is made up of an {Queue, Binding, Exchange} +-record(reverse_binding, {binding, value = const}). --record(binding, {exchange, key, queue}). +-record(binding, {virtual_host, exchange_name, key, queue_name}). -record(listener, {node, protocol, host, port}). diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 897d063d21..ad17a42eb2 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -167,14 +167,17 @@ recover_queue(Q) -> ok. default_binding_spec(#resource{virtual_host = VHostPath, name = Name}) -> - exit(default_binding_spec). + #binding{exchange_name = <<"">>, + key = Name, + queue_name = Name, + virtual_host = VHostPath}. % #binding_spec{exchange_name = rabbit_misc:r(VHostPath,exchange,<<"">>), % routing_key = Name, % arguments = []}. recover_bindings(Q = #amqqueue{name = QueueName}) -> - exit(recover_bindings). - % ok = rabbit_exchange:add_binding(default_binding_spec(QueueName), Q), + io:format("Q was ~p~n",[Q]), + ok = rabbit_exchange:add_binding(default_binding_spec(QueueName)). % lists:foreach(fun (B) -> % ok = rabbit_exchange:add_binding(B, Q) % end, Specs), diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index b7113a6f11..eb8977f9b4 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -221,11 +221,13 @@ delivery_key_for_type(_Type, Name, RoutingKey) -> % Don't really like this double lookup % It seems very clunky % Can this get refactored to to avoid the duplication of the lookup/1 function? -call_with_exchange_and_queue(Exchange, Queue, Fun) -> - case mnesia:wread({exchange, Exchange}) of +call_with_exchange_and_queue(#binding{virtual_host = VHost, exchange_name = Exchange, + queue_name = Queue}, Fun) -> + io:format("Reading (~p) and (~p) ~n",[Exchange,Queue]), + case mnesia:wread({exchange, rabbit_misc:r(VHost, exchange, Exchange)}) of [] -> {error, exchange_not_found}; [X] -> - case mnesia:wread({amqqueue, Queue}) of + case mnesia:wread({amqqueue, rabbit_misc:r(VHost, amqqueue, Queue)}) of [] -> {error, queue_not_found}; [Q] -> Fun(X,Q) @@ -237,13 +239,13 @@ make_handler(BindingSpec, #amqqueue{name = QueueName, pid = QPid}) -> exit(make_handler). %#handler{binding_spec = BindingSpec, queue = QueueName, qpid = QPid}. -add_binding(#binding{exchange = Exchange, key = Key, queue = Queue}) -> +add_binding(Binding) -> call_with_exchange_and_queue( - Exchange, Queue, + Binding, fun (X,Q) -> if Q#amqqueue.durable and not(X#exchange.durable) -> {error, durability_settings_incompatible}; true -> - internal_add_binding(X, Key, Q) + internal_add_binding(Binding) end end). @@ -278,14 +280,18 @@ handler_qpids(Handlers) -> exit(handler_qpids). %sets:from_list([QPid || #handler{qpid = QPid} <- Handlers]). -%% Must run within a transaction. -internal_add_binding(#exchange{name = ExchangeName, type = Type}, - RoutingKey, Queue) -> - ok. - %BindingKey = delivery_key_for_type(Type, ExchangeName, RoutingKey), - %ok = add_handler_to_binding(BindingKey, Handler). +reverse_binding(#binding{virtual_host = VHost, exchange_name = Exchange, + key = Key, queue_name = Queue}) -> + {binding, VHost, Queue, Key, Exchange}. %% Must run within a transaction. +internal_add_binding(Binding) -> + Forwards = #forwards_binding{ binding = Binding }, + Reverse = #reverse_binding{ binding = reverse_binding(Binding) }, + ok = mnesia:write(Forwards), + ok = mnesia:write(Reverse). + +%% Must run within a transaction. internal_delete_binding(#exchange{name = ExchangeName, type = Type}, RoutingKey, Handler) -> BindingKey = delivery_key_for_type(Type, ExchangeName, RoutingKey), remove_handler_from_binding(BindingKey, Handler), |
