Merge bug25466

This commit is contained in:
Simon MacMullen 2013-03-07 15:04:19 +00:00
commit 412e594fa0
2 changed files with 79 additions and 52 deletions

View File

@ -443,7 +443,17 @@ with_destination(Command, Frame, State, Fun) ->
{ok, DestHdr} -> {ok, DestHdr} ->
case rabbit_routing_util:parse_endpoint(DestHdr) of case rabbit_routing_util:parse_endpoint(DestHdr) of
{ok, Destination} -> {ok, Destination} ->
Fun(Destination, DestHdr, Frame, State); case Fun(Destination, DestHdr, Frame, State) of
{error, invalid_endpoint} ->
error("Invalid destination",
"'~s' is not a valid destination for '~s'~n",
[DestHdr, Command],
State);
{error, Reason} ->
throw(Reason);
Result ->
Result
end;
{error, {invalid_destination, Type, Content}} -> {error, {invalid_destination, Type, Content}} ->
error("Invalid destination", error("Invalid destination",
"'~s' is not a valid ~p destination~n", "'~s' is not a valid ~p destination~n",
@ -540,14 +550,11 @@ do_subscribe(Destination, DestHdr, Frame,
global = false}), global = false}),
Channel1 Channel1
end, end,
{AckMode, IsMulti} = rabbit_stomp_util:ack_mode(Frame), {AckMode, IsMulti} = rabbit_stomp_util:ack_mode(Frame),
case ensure_endpoint(source, Destination, Frame, Channel, RouteState) of
{ok, Queue, RouteState1} = {ok, Queue, RouteState1} ->
ensure_endpoint(source, Destination, Frame, Channel, RouteState), {ok, ConsumerTag, Description} =
rabbit_stomp_util:consumer_tag(Frame),
{ok, ConsumerTag, Description} = rabbit_stomp_util:consumer_tag(Frame),
amqp_channel:subscribe(Channel, amqp_channel:subscribe(Channel,
#'basic.consume'{ #'basic.consume'{
queue = Queue, queue = Queue,
@ -557,23 +564,29 @@ do_subscribe(Destination, DestHdr, Frame,
exclusive = false}, exclusive = false},
self()), self()),
ExchangeAndKey = rabbit_routing_util:parse_routing(Destination), ExchangeAndKey = rabbit_routing_util:parse_routing(Destination),
ok = rabbit_routing_util:ensure_binding(Queue, ExchangeAndKey, Channel), ok = rabbit_routing_util:ensure_binding(
Queue, ExchangeAndKey, Channel),
ok(State#state{subscriptions = ok(State#state{subscriptions =
dict:store(ConsumerTag, dict:store(
ConsumerTag,
#subscription{dest_hdr = DestHdr, #subscription{dest_hdr = DestHdr,
channel = Channel, channel = Channel,
ack_mode = AckMode, ack_mode = AckMode,
multi_ack = IsMulti, multi_ack = IsMulti,
description = Description}, description = Description},
Subs), Subs),
route_state = RouteState1}). route_state = RouteState1});
{error, _} = Err ->
Err
end.
do_send(Destination, _DestHdr, do_send(Destination, _DestHdr,
Frame = #stomp_frame{body_iolist = BodyFragments}, Frame = #stomp_frame{body_iolist = BodyFragments},
State = #state{channel = Channel, route_state = RouteState}) -> State = #state{channel = Channel, route_state = RouteState}) ->
{ok, _Q, RouteState1} = ensure_endpoint(dest, Destination, Frame, Channel,
RouteState), case ensure_endpoint(dest, Destination, Frame, Channel, RouteState) of
{ok, _Q, RouteState1} ->
{Frame1, State1} = {Frame1, State1} =
ensure_reply_to(Frame, State#state{route_state = RouteState1}), ensure_reply_to(Frame, State#state{route_state = RouteState1}),
@ -591,7 +604,8 @@ do_send(Destination, _DestHdr,
case transactional(Frame1) of case transactional(Frame1) of
{yes, Transaction} -> {yes, Transaction} ->
extend_transaction(Transaction, extend_transaction(
Transaction,
fun(StateN) -> fun(StateN) ->
maybe_record_receipt(Frame1, StateN) maybe_record_receipt(Frame1, StateN)
end, end,
@ -600,6 +614,11 @@ do_send(Destination, _DestHdr,
no -> no ->
ok(send_method(Method, Props, BodyFragments, ok(send_method(Method, Props, BodyFragments,
maybe_record_receipt(Frame1, State1))) maybe_record_receipt(Frame1, State1)))
end;
{error, _} = Err ->
Err
end. end.
create_ack_method(DeliveryTag, #subscription{multi_ack = IsMulti}) -> create_ack_method(DeliveryTag, #subscription{multi_ack = IsMulti}) ->

View File

@ -35,7 +35,8 @@ all_tests() ->
fun test_subscribe_ack/3, fun test_subscribe_ack/3,
fun test_send/3, fun test_send/3,
fun test_delete_queue_subscribe/3, fun test_delete_queue_subscribe/3,
fun test_temp_destination_queue/3]] fun test_temp_destination_queue/3,
fun test_temp_destination_in_send/3]]
|| Version <- ?SUPPORTED_VERSIONS], || Version <- ?SUPPORTED_VERSIONS],
ok. ok.
@ -200,6 +201,13 @@ test_temp_destination_queue(Channel, Client, _Version) ->
{ok, _Client1, _, [<<"pong">>]} = stomp_receive(Client, "MESSAGE"), {ok, _Client1, _, [<<"pong">>]} = stomp_receive(Client, "MESSAGE"),
ok. ok.
test_temp_destination_in_send(Channel, Client, _Version) ->
rabbit_stomp_client:send( Client, "SEND", [{"destination", "/temp-queue/foo"}],
["poing"]),
{ok, _Client1, Hdrs, _} = stomp_receive(Client, "ERROR"),
"Invalid destination" = proplists:get_value("message", Hdrs),
ok.
stomp_receive(Client, Command) -> stomp_receive(Client, Command) ->
{#stomp_frame{command = Command, {#stomp_frame{command = Command,
headers = Hdrs, headers = Hdrs,