Commits

Anonymous committed 8734da6

Pass NoAck option through gen_bunny.

Comments (0)

Files changed (2)

src/example_gb.erl

 -behavior(gen_bunny).
 
 -export([start_link/0,
+         start_link/3,
          init/1,
          handle_message/2,
          handle_call/3,
 -record(state, {messages=[]}).
 
 start_link() ->
-    gen_bunny:start_link(?MODULE, direct,
-                         <<"bunny.test">>, []).
+    start_link(direct, <<"bunny.test">>, []).
+
+start_link(Conn, Declare, Opts) ->
+    gen_bunny:start_link(?MODULE, Conn, Declare, Opts).
+
 
 init([]) ->
     {ok, #state{}}.

src/gen_bunny.erl

     gen_server:cast(Dest, Request).
 
 
-init([Module, ConnectionInfo, DeclareInfo, InitArgs]) ->
-    case Module:init(InitArgs) of
+init([Module, ConnectionInfo, DeclareInfo, InitArgs0]) ->
+    {NoAck, InitArgs1} = get_opt(no_ack, InitArgs0, true),
+    case Module:init(InitArgs1) of
         {ok, ModState} ->
-            case connect_declare_subscribe(ConnectionInfo, DeclareInfo) of
+            case connect_declare_subscribe(
+                   ConnectionInfo, DeclareInfo, NoAck) of
                 {ok, ConnectionPid, ChannelPid, QueueName} ->
                     %% TODO:  monitor channel/connection pids?
                     {ok, #state{mod=Module,
     {ok, State}.
 
 %% TODO: better error handling here.
-connect_declare_subscribe(ConnectionInfo, DeclareInfo) ->
+connect_declare_subscribe(ConnectionInfo, DeclareInfo, NoAck) ->
     %% TODO: link?
     case catch bunny_util:connect(ConnectionInfo) of
         {'EXIT', {Reason, _Stack}} ->
                     QueueName = bunny_util:get_name(Queue),
                     lib_amqp:subscribe(ChannelPid,
                                        QueueName,
-                                       self()),
+                                       self(), NoAck),
                     {ok, ConnectionPid, ChannelPid, QueueName}
             end
     end.
+
+get_opt(Opt, Proplist) ->
+    get_opt(Opt, Proplist, undefined).
+
+get_opt(Opt, Proplist, Default) ->
+    {proplists:get_value(Opt, Proplist, Default),
+     proplists:delete(Opt, Proplist)}.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.