Current section

113 Versions

Jump to

Compare versions

4 files changed
+26 additions
-6 deletions
  @@ -29,4 +29,4 @@
29 29 [{<<"app">>,<<"snappyer">>},
30 30 {<<"optional">>,false},
31 31 {<<"requirement">>,<<"1.2.9">>}]}]}.
32 - {<<"version">>,<<"3.18.0">>}.
32 + {<<"version">>,<<"3.19.0">>}.
  @@ -1,6 +1,6 @@
1 1 {application,brod,
2 2 [{description,"Apache Kafka Erlang client library"},
3 - {vsn,"3.18.0"},
3 + {vsn,"3.19.0"},
4 4 {registered,[]},
5 5 {applications,[kernel,stdlib,kafka_protocol,snappyer]},
6 6 {env,[]},
  @@ -22,7 +22,7 @@
22 22 -include("brod_int.hrl").
23 23
24 24 %% brod_topic_subscriber callbacks
25 - -export([init/2, handle_message/3, terminate/2]).
25 + -export([init/2, handle_message/3, handle_info/2, terminate/2]).
26 26
27 27 -type start_options() ::
28 28 #{ group_id := brod:group_id()
  @@ -91,6 +91,15 @@ handle_message(_Partition, Msg, State) ->
91 91 {ok, NewState}
92 92 end.
93 93
94 + handle_info(Info, #state{cb_module = CbModule , cb_state = CbState} = State) ->
95 + %% Any unhandled messages are forwarded to the callback module to
96 + %% support arbitrary message-passing.
97 + %% Only the {noreply, State} return value is supported.
98 + case brod_utils:optional_callback(CbModule, handle_info, [Info, CbState], {noreply, CbState}) of
99 + {noreply, NewCbState} ->
100 + {noreply, State#state{cb_state = NewCbState}}
101 + end.
102 +
94 103 terminate(Reason, #state{cb_module = CbModule, cb_state = State}) ->
95 104 brod_utils:optional_callback(CbModule, terminate, [Reason, State], ok).
  @@ -108,7 +108,12 @@
108 108 %% This callback is called before stopping the subscriber
109 109 -callback terminate(_Reason, cb_state()) -> _.
110 110
111 - -optional_callbacks([terminate/2]).
111 + %% This callback is called when the subscriber receives a message unrelated to
112 + %% the subscription.
113 + %% The callback must return `{noreply, NewCallbackState}'.
114 + -callback handle_info(_Msg, cb_state()) -> {noreply, cb_state()}.
115 +
116 + -optional_callbacks([terminate/2, handle_info/2]).
112 117
113 118 %%%_* Types and macros =========================================================
114 119
  @@ -357,8 +362,14 @@ handle_info({'DOWN', _Mref, process, Pid, Reason},
357 362 %% not a consumer pid
358 363 {noreply, State}
359 364 end;
360 - handle_info(_Info, State) ->
361 - {noreply, State}.
365 + handle_info(Info, #state{cb_module = CbModule, cb_state = CbState} = State) ->
366 + %% Any unhandled messages are forwarded to the callback module to
367 + %% support arbitrary message-passing.
368 + %% Only the {noreply, State} return value is supported.
369 + case brod_utils:optional_callback(CbModule, handle_info, [Info, CbState], {noreply, CbState}) of
370 + {noreply, NewCbState} ->
371 + {noreply, State#state{cb_state = NewCbState}}
372 + end.
362 373
363 374 %% @private
364 375 handle_call(Call, _From, State) ->