Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publisher channel #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/turtle_publisher.erl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ handle_info({gproc, Ref, registered, {_, Pid, _}}, {initializing, N, Ref, CName,
ok = handle_confirms(Channel, Options),
{ok, ReplyQueue, Tag} = handle_rpc(Channel, Options),
ConnMRef = monitor(process, Pid),
_ = monitor(process, Channel),
reg(N),
{noreply,
#state {
Expand All @@ -240,6 +241,7 @@ handle_info({gproc, Ref, registered, {_, Pid, _}}, {initializing_takeover, N, Re
ok = handle_confirms(Channel, Options),
{ok, ReplyQueue, Tag} = handle_rpc(Channel, Options),
ConnMRef = monitor(process, Pid),
_ = monitor(process, Channel),
case where(N) of
undefined ->
reg(N);
Expand Down Expand Up @@ -274,6 +276,8 @@ handle_info({channel_closed, Ch, Reason}, #state { channel = Ch } = State) ->
{stop, Exit, State};
handle_info({'DOWN', MRef, process, _, Reason}, #state { conn_ref = MRef } = State) ->
{stop, {error, {connection_down, Reason}}, State};
handle_info({'DOWN', _, process, Pid, Reason}, #state { channel = Pid } = State) ->
{stop, {error, {channel_died, Reason}}, State};
handle_info({'DOWN', MRef, process, _, _Reason}, #state { in_flight = IF } = State) ->
%% Remove in-flight monitor if the RPC caller goes away
{noreply, State#state { in_flight = track_cancel_monitor(MRef, IF) }};
Expand Down Expand Up @@ -352,7 +356,8 @@ properties(ContentType, #{}) ->
#'P_basic' { content_type = ContentType }.

%% Create a new publish package
mk_publish(Exch, Key, ContentType, IODataPayload, Opts) ->
mk_publish(Exch, Key, ContentType, IODataPayload, Opts) when is_binary(Exch), is_binary(Key),
ContentType =:= undefined orelse is_binary(ContentType) ->
Pub = #'basic.publish' {
exchange = Exch,
routing_key = Key
Expand Down