diff options
| author | Matthias Radestock <matthias@rabbitmq.com> | 2012-04-10 15:36:30 +0100 |
|---|---|---|
| committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-04-10 15:36:30 +0100 |
| commit | 5a9edce39417f243bbfc08bd2545d1d14ac26c98 (patch) | |
| tree | 8f1e2348acb342c6d64cdf97c436c527666a804c /src | |
| parent | 44d12f1074bcb06d58fa8f979ce9afc2b515e6b2 (diff) | |
| parent | b4f0c71ffcce6e3b400942c55c42da738b5fc0bf (diff) | |
| download | rabbitmq-server-git-5a9edce39417f243bbfc08bd2545d1d14ac26c98.tar.gz | |
merge bug24846 into default
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_amqqueue_process.erl | 38 | ||||
| -rw-r--r-- | src/rabbit_basic.erl | 13 |
2 files changed, 29 insertions, 22 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index 21e576a653..eb9ee8353a 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -830,29 +830,33 @@ make_dead_letter_msg(DLX, Reason, exchange_name = Exchange, routing_keys = RoutingKeys}, State = #q{dlx_routing_key = DlxRoutingKey}) -> - Headers = rabbit_basic:extract_headers(Content), - #resource{name = QName} = qname(State), - %% The first routing key is the one specified in the - %% basic.publish; all others are CC or BCC keys. - RoutingKeys1 = [hd(RoutingKeys) | rabbit_basic:header_routes(Headers)], - Info = [{<<"reason">>, longstr, list_to_binary(atom_to_list(Reason))}, - {<<"queue">>, longstr, QName}, - {<<"time">>, timestamp, rabbit_misc:now_ms() div 1000}, - {<<"exchange">>, longstr, Exchange#resource.name}, - {<<"routing-keys">>, array, - [{longstr, Key} || Key <- RoutingKeys1]}], - Headers1 = rabbit_basic:append_table_header(<<"x-death">>, Info, Headers), - {DeathRoutingKeys, Headers2} = + {DeathRoutingKeys, HeadersFun1} = case DlxRoutingKey of - undefined -> {RoutingKeys, Headers1}; + undefined -> {RoutingKeys, fun (H) -> H end}; _ -> {[DlxRoutingKey], - lists:keydelete(<<"CC">>, 1, Headers1)} + fun (H) -> lists:keydelete(<<"CC">>, 1, H) end} + end, + #resource{name = QName} = qname(State), + HeadersFun2 = + fun (Headers) -> + %% The first routing key is the one specified in the + %% basic.publish; all others are CC or BCC keys. + RoutingKeys1 = + [hd(RoutingKeys) | rabbit_basic:header_routes(Headers)], + Info = [{<<"reason">>, + longstr, list_to_binary(atom_to_list(Reason))}, + {<<"queue">>, longstr, QName}, + {<<"time">>, timestamp, rabbit_misc:now_ms() div 1000}, + {<<"exchange">>, longstr, Exchange#resource.name}, + {<<"routing-keys">>, array, + [{longstr, Key} || Key <- RoutingKeys1]}], + HeadersFun1(rabbit_basic:append_table_header(<<"x-death">>, + Info, Headers)) end, - Content1 = rabbit_basic:replace_headers(Headers2, Content), + Content1 = rabbit_basic:map_headers(HeadersFun2, Content), Msg#basic_message{exchange_name = DLX, id = rabbit_guid:gen(), routing_keys = DeathRoutingKeys, content = Content1}. - now_micros() -> timer:now_diff(now(), {0,0,0}). infos(Items, State) -> diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index a89aa07407..8ad5901629 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -20,7 +20,7 @@ -export([publish/4, publish/6, publish/1, message/3, message/4, properties/1, append_table_header/3, - extract_headers/1, replace_headers/2, delivery/4, header_routes/1]). + extract_headers/1, map_headers/2, delivery/4, header_routes/1]). -export([build_content/2, from_content/1]). %%---------------------------------------------------------------------------- @@ -63,8 +63,8 @@ -spec(extract_headers/1 :: (rabbit_types:content()) -> headers()). --spec(replace_headers/2 :: (headers(), rabbit_types:content()) - -> rabbit_types:content()). +-spec(map_headers/2 :: (rabbit_types:content(), fun((headers()) -> headers())) + -> rabbit_types:content()). -spec(header_routes/1 :: (undefined | rabbit_framing:amqp_table()) -> [string()]). @@ -193,9 +193,12 @@ extract_headers(Content) -> rabbit_binary_parser:ensure_content_decoded(Content), Headers. -replace_headers(Headers, Content = #content{properties = Props}) -> +map_headers(F, Content) -> + Content1 = rabbit_binary_parser:ensure_content_decoded(Content), + #content{properties = #'P_basic'{headers = Headers} = Props} = Content1, + Headers1 = F(Headers), rabbit_binary_generator:clear_encoded_content( - Content#content{properties = Props#'P_basic'{headers = Headers}}). + Content1#content{properties = Props#'P_basic'{headers = Headers1}}). indexof(L, Element) -> indexof(L, Element, 1). |
