Skip to content

Commit

Permalink
Added NA's change to persist messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Cameron committed Sep 19, 2013
1 parent 5e383f7 commit d49cb14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 56 deletions.
31 changes: 0 additions & 31 deletions src/rabbithub.erl
Original file line number Diff line number Diff line change
Expand Up @@ -213,37 +213,6 @@ deliver_via_post(#rabbithub_subscription{callback = Callback},
end.


%% deliver_via_post(#rabbithub_subscription{callback = Callback},
%% #basic_message{routing_keys = [RoutingKeyBin | _],
%% content = Content0 = #content{payload_fragments_rev = PayloadRev}},
%% ExtraHeaders) ->
%% ExtraQuery = mochiweb_util:urlencode([{'hub.topic', RoutingKeyBin}]),
%% %% FIXME: Put more content properties into the post.
%% #content{properties = #'P_basic'{content_type = ContentTypeBin}} =
%% rabbit_binary_parser:ensure_content_decoded(Content0),
%% PayloadBin = list_to_binary(lists:reverse(PayloadRev)),
%% case simple_httpc:req("POST",
%% Callback,
%% ExtraQuery,
%% [{"Content-length", integer_to_list(size(PayloadBin))},
%% {"Content-type", case ContentTypeBin of
%% undefined -> "application/octet-stream";
%% _ -> binary_to_list(ContentTypeBin)
%% end},
%% {"X-AMQP-Routing-Key", RoutingKeyBin}
%% | ExtraHeaders],
%% PayloadBin) of
%% {ok, StatusCode, _StatusText, _Headers, _Body} ->
%% if
%% StatusCode >= 200 andalso StatusCode < 300 ->
%% {ok, StatusCode};
%% true ->
%% {error, StatusCode}
%% end;
%% {error, Reason} ->
%% {error, Reason}
%% end.

error_and_unsub(Subscription, ErrorReport) ->
rabbit_log:error("RabbitHub unsubscribing~n~p~n", [ErrorReport]),
rabbithub_subscription:delete(Subscription),
Expand Down
36 changes: 11 additions & 25 deletions src/rabbithub_web.erl
Original file line number Diff line number Diff line change
Expand Up @@ -399,30 +399,6 @@ do_validate(Callback, Topic, LeaseSeconds, ActualUse, VerifyToken) ->
{error, invalid_callback_url}
end.

%% do_validate(Callback, Topic, LeaseSeconds, ActualUse, VerifyToken) ->
%% Challenge = list_to_binary(rabbithub:b64enc(rabbit_guid:binary(rabbit_guid:gen(), "c"))),
%% Params0 = [{'hub.mode', ActualUse},
%% {'hub.topic', Topic},
%% {'hub.challenge', Challenge},
%% {'hub.lease_seconds', LeaseSeconds}],
%% Params = case VerifyToken of
%% none -> Params0;
%% _ -> [{'hub.verify_token', VerifyToken} | Params0]
%% end,
%% case simple_httpc:req("GET", Callback, mochiweb_util:urlencode(Params), [], []) of
%% {ok, StatusCode, _StatusText, _Headers, Body}
%% when StatusCode >= 200 andalso StatusCode < 300 ->
%% if
%% Body =:= Challenge ->
%% ok;
%% true ->
%% {error, challenge_mismatch}
%% end;
%% {ok, StatusCode, _StatusText, _Headers, _Body} ->
%% {error, {request_status, StatusCode}};
%% {error, Reason} ->
%% {error, Reason}
%% end.

invoke_sub_fun_and_respond(Req, Fun, Callback, Topic, LeaseSeconds, MaybeShortcut) ->
case Fun(Callback, Topic, LeaseSeconds, MaybeShortcut) of
Expand Down Expand Up @@ -533,16 +509,26 @@ validate_subscription_request(Req, ParsedQuery, SourceResource, ActualUse, Fun)
end
end.

% QueryString hub.persistmsg = 0, DeliveryMode = 1 -> non-persistent message
% QueryString hub.persistmsg = 1, DeliveryMode = 2 -> persistent message (saved to disk)
get_msg_delivery_mode(PersistMsg) ->
case PersistMsg of
"1" -> 2;
"0" -> 1
end.

extract_message(ExchangeResource, ParsedQuery, Req) ->
RoutingKey = param(ParsedQuery, "hub.topic", ""),
DeliveryMode = get_msg_delivery_mode(param(ParsedQuery, "hub.persistmsg", "0")),
ContentTypeBin = case Req:get_header_value("content-type") of
undefined -> undefined;
S -> list_to_binary(S)
end,
Body = Req:recv_body(),
%% rabbit_log:info("RabbitHub message delivery mode: ~p~n", [DeliveryMode]),
rabbit_basic:message(ExchangeResource,
list_to_binary(RoutingKey),
[{'content_type', ContentTypeBin}],
[{'content_type', ContentTypeBin},{'delivery_mode',DeliveryMode}],
Body).

perform_request('POST', endpoint, '', exchange, Resource, ParsedQuery, Req) ->
Expand Down

0 comments on commit d49cb14

Please sign in to comment.