diff options
| author | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-01-24 12:22:59 +0000 |
|---|---|---|
| committer | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-01-24 12:22:59 +0000 |
| commit | 78f61fde6589b01a88a0cf9bb7f682c51089d407 (patch) | |
| tree | 40940a07eefbc1e3b47088dfe0e1481b5f205989 | |
| parent | aee2983d79bde3725ebdaf5e71e9f1dee4115d52 (diff) | |
| download | rabbitmq-server-git-78f61fde6589b01a88a0cf9bb7f682c51089d407.tar.gz | |
Add stub for "inert" exchange to be used when exchange types are missing.
Right now it just emits warnings on startup and when a message is routed
through the exchange.
I need to handle the "add_binding" and "remove_bindings" better, probably
emitting a protocol error.
Also, I'm not sure the log warning are visible enough.
| -rw-r--r-- | src/rabbit_exchange.erl | 15 | ||||
| -rw-r--r-- | src/rabbit_exchange_type_inert.erl | 43 |
2 files changed, 55 insertions, 3 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index a15b9be490..8b2015967a 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -355,11 +355,20 @@ peek_serial(XName) -> _ -> undefined end. +inert_module(T) -> + rabbit_log:warning( + "Could not find exchange type ~p, using inert exchange instead~n", [T]), + put({xtype_to_module, T}, rabbit_exchange_type_inert), + rabbit_exchange_type_inert. + %% Used with atoms from records; e.g., the type is expected to exist. type_to_module(T) -> case get({xtype_to_module, T}) of - undefined -> {ok, Module} = rabbit_registry:lookup_module(exchange, T), - put({xtype_to_module, T}, Module), - Module; + undefined -> + case rabbit_registry:lookup_module(exchange, T) of + {ok, Module} -> put({xtype_to_module, T}, Module), + Module; + {error, not_found} -> inert_module(T) + end; Module -> Module end. diff --git a/src/rabbit_exchange_type_inert.erl b/src/rabbit_exchange_type_inert.erl new file mode 100644 index 0000000000..9e2424e9b3 --- /dev/null +++ b/src/rabbit_exchange_type_inert.erl @@ -0,0 +1,43 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is VMware, Inc. +%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. +%% + +-module(rabbit_exchange_type_inert). +-include("rabbit.hrl"). + +-behaviour(rabbit_exchange_type). + +-export([description/0, serialise_events/0, route/2]). +-export([validate/1, create/2, delete/3, + add_binding/3, remove_bindings/3, assert_args_equivalence/2]). +-include("rabbit_exchange_type_spec.hrl"). + +description() -> + D = <<"Dummy exchange type, to be used when the intended one is not found">>, + [{name, <<"inert">>}, {description, D}]. + +serialise_events() -> false. + +route(#exchange{name = Name}, _) -> + rabbit_log:warning("Received message at inert exchange ~p, dropping~n", + [Name]). + +validate(_X) -> ok. +create(_Tx, _X) -> ok. +delete(_Tx, _X, _Bs) -> ok. +add_binding(_Tx, _X, _B) -> ok. +remove_bindings(_Tx, _X, _Bs) -> ok. +assert_args_equivalence(X, Args) -> + rabbit_exchange:assert_args_equivalence(X, Args). |
