summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-05-19 19:11:31 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-05-19 19:11:31 +0100
commita93d3d23fb1768ff6b1518052ee7cf12cf4c30f2 (patch)
tree301b066f226da6f3313f6007a18bd2ee7ce57d50
parentb52f2ffca60521f21f4dc74d3ec0dccc754e6764 (diff)
downloadrabbitmq-server-a93d3d23fb1768ff6b1518052ee7cf12cf4c30f2.tar.gz
inlining
-rw-r--r--src/rabbit_trace.erl57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/rabbit_trace.erl b/src/rabbit_trace.erl
index 36125376..ab6ef982 100644
--- a/src/rabbit_trace.erl
+++ b/src/rabbit_trace.erl
@@ -36,7 +36,10 @@
%%----------------------------------------------------------------------------
init(VHost) ->
- trace_exchange(VHost).
+ case application:get_env(rabbit, trace_exchanges) of
+ undefined -> none;
+ {ok, Xs} -> proplists:get_value(VHost, Xs, none)
+ end.
tap_trace_in(Msg, TraceX) ->
maybe_trace(Msg, TraceX, <<"publish">>, xname(Msg), []).
@@ -47,44 +50,39 @@ tap_trace_out({#resource{name = QName}, _QPid, _QMsgId, Redelivered, Msg},
maybe_trace(Msg, TraceX, <<"deliver">>, QName,
[{<<"redelivered">>, signedint, RedeliveredNum}]).
-xname(#basic_message{exchange_name = #resource{name = XName}}) -> XName.
-vhost(#basic_message{exchange_name = #resource{virtual_host = VHost}}) -> VHost.
-
maybe_trace(_Msg, none, _RKPrefix, _RKSuffix, _Extra) ->
ok;
-maybe_trace(Msg0, TraceX, RKPrefix, RKSuffix, Extra) ->
- case xname(Msg0) of
+maybe_trace(Msg, TraceX, RKPrefix, RKSuffix, Extra) ->
+ case xname(Msg) of
TraceX -> ok;
- _ -> Msg = ensure_content_decoded(Msg0),
- X = rabbit_misc:r(vhost(Msg), exchange, TraceX),
- RKey = <<RKPrefix/binary, ".", RKSuffix/binary>>,
- P = #'P_basic'{headers = msg_to_table(Msg) ++ Extra},
- case catch rabbit_basic:publish(X, RKey, P, payload(Msg)) of
+ _ -> 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
end.
-trace_exchange(VHost) ->
- case application:get_env(rabbit, trace_exchanges) of
- undefined -> none;
- {ok, Xs} -> proplists:get_value(VHost, Xs, none)
- 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,
- content = #content{properties = Props}}) ->
+ content = Content}) ->
+ #content{properties = Props} =
+ rabbit_binary_parser:ensure_content_decoded(Content),
{PropsTable, _Ix} =
- lists:foldl(
- fun (K, {L, Ix}) ->
- V = element(Ix, Props),
- NewL = case V of
- undefined -> L;
- _ -> [{a2b(K), type(V), V} | L]
- end,
- {NewL, Ix + 1}
- end, {[], 2}, record_info(fields, 'P_basic')),
+ lists:foldl(fun (K, {L, Ix}) ->
+ V = element(Ix, Props),
+ NewL = case V of
+ undefined -> L;
+ _ -> [{a2b(K), type(V), V} | L]
+ end,
+ {NewL, Ix + 1}
+ end, {[], 2}, record_info(fields, 'P_basic')),
[{<<"exchange_name">>, longstr, XName},
{<<"routing_keys">>, array, [{longstr, K} || K <- RoutingKeys]},
{<<"properties">>, table, PropsTable},
@@ -93,12 +91,7 @@ msg_to_table(#basic_message{exchange_name = #resource{name = XName},
payload(#basic_message{content = #content{payload_fragments_rev = PFR}}) ->
list_to_binary(lists:reverse(PFR)).
-ensure_content_decoded(Msg = #basic_message{content = Content}) ->
- Msg#basic_message{content = rabbit_binary_parser:ensure_content_decoded(
- Content)}.
-
-a2b(A) ->
- list_to_binary(atom_to_list(A)).
+a2b(A) -> list_to_binary(atom_to_list(A)).
type(V) when is_list(V) -> table;
type(V) when is_integer(V) -> signedint;