diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-05-19 19:50:38 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-05-19 19:50:38 +0100 |
commit | c86418efd720f04ceaa2ee3b208688e179039929 (patch) | |
tree | fc302ed099b48d10bd7b6cf15999b487031f661d | |
parent | a93d3d23fb1768ff6b1518052ee7cf12cf4c30f2 (diff) | |
download | rabbitmq-server-c86418efd720f04ceaa2ee3b208688e179039929.tar.gz |
fix error handling and construct xname on init rather than every message
I have no idea why that 'catch' was there. There is nothing to go
wrong during publish except the exchange may not be found. Which the
'catch' wasn't catching since that is just an ordinary {error,
not_found} return. Cue explosion. So now we handle that and print a
nice error message.
Also, there is no point constructing the exchange name for every
message; doing that once, on init, is enough. That has the further
advantage that now the implementation matches the spec
(rabbit_exchange:name() is a qualified name, not a binary).
-rw-r--r-- | src/rabbit_trace.erl | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/rabbit_trace.erl b/src/rabbit_trace.erl index ab6ef982..9543f8de 100644 --- a/src/rabbit_trace.erl +++ b/src/rabbit_trace.erl @@ -25,7 +25,7 @@ -ifdef(use_specs). --type(state() :: rabbit_exchange:name()). +-type(state() :: rabbit_exchange:name() | 'none'). -spec(init/1 :: (rabbit_types:vhost()) -> state()). -spec(tap_trace_in/2 :: (rabbit_types:basic_message(), state()) -> 'ok'). @@ -38,7 +38,10 @@ init(VHost) -> case application:get_env(rabbit, trace_exchanges) of undefined -> none; - {ok, Xs} -> proplists:get_value(VHost, Xs, none) + {ok, Xs} -> case proplists:get_value(VHost, Xs, none) of + none -> none; + XN -> rabbit_misc:r(VHost, exchange, XN) + end end. tap_trace_in(Msg, TraceX) -> @@ -52,22 +55,21 @@ tap_trace_out({#resource{name = QName}, _QPid, _QMsgId, Redelivered, Msg}, maybe_trace(_Msg, none, _RKPrefix, _RKSuffix, _Extra) -> ok; -maybe_trace(Msg, TraceX, RKPrefix, RKSuffix, Extra) -> +maybe_trace(Msg, X, RKPrefix, RKSuffix, Extra) -> case xname(Msg) of - TraceX -> ok; - _ -> case catch rabbit_basic:publish( - rabbit_misc:r(vhost(Msg), exchange, TraceX), - <<RKPrefix/binary, ".", RKSuffix/binary>>, - #'P_basic'{headers = msg_to_table(Msg) ++ Extra}, - payload(Msg)) of - {'EXIT', R} -> rabbit_log:info( - "Trace publish died: ~p~n", [R]); - {ok, _, _} -> ok - end + X -> ok; + _ -> case rabbit_basic:publish( + X, + <<RKPrefix/binary, ".", RKSuffix/binary>>, + #'P_basic'{headers = msg_to_table(Msg) ++ Extra}, + payload(Msg)) of + {ok, _, _} -> ok; + {error, not_found} -> rabbit_log:info("trace ~s not found~n", + [rabbit_misc:rs(X)]) + end end. xname(#basic_message{exchange_name = #resource{name = XName}}) -> XName. -vhost(#basic_message{exchange_name = #resource{virtual_host = VHost}}) -> VHost. msg_to_table(#basic_message{exchange_name = #resource{name = XName}, routing_keys = RoutingKeys, |