2828
2929-export ([ produce /4
3030 , produce /5
31+ , produce /6
3132 ]).
3233
3334-export ([ metadata /2
5152
5253-export ([ encode /3
5354 , make /3
55+ , make /4
5456 ]).
5557
5658-export_type ([ fetch_opts / 0
@@ -250,17 +252,20 @@ fetch(Vsn, Topic, Partition, Offset, Opts) ->
250252 make (fetch , Vsn , Fields ).
251253
252254% % @doc Help function to construct a non-transactional produce request.
253- % % `Batch' arg can be be a `[map()]' like `[#{key => Key, value => Value, ts => Ts}]'.
254- % % Current system time will be taken if `ts' is missing in batch input.
255- % % It may also be `binary()' or `{magic_v2, Bytes, iolist()}' if user choose to encode
256- % % a batch beforehand which could be helpful when a large batch can be encoded
257- % % in other processes.
255+ % % @see produce/6.
258256-spec produce (vsn (), topic (), partition (),
259257 binary () | batch_input () | {magic_v2 , non_neg_integer (), iolist ()}) -> req ().
260258produce (Vsn , Topic , Partition , Batch ) ->
261259 produce (Vsn , Topic , Partition , Batch , #{}).
262260
263261% % @doc Help function to construct a produce request.
262+ % % @see produce/6.
263+ -spec produce (vsn (), topic (), partition (),
264+ binary () | batch_input () | {magic_v2 , non_neg_integer (), iolist ()}, produce_opts ()) -> req ().
265+ produce (Vsn , Topic , Partition , Batch , Opts ) when is_map (Opts ) ->
266+ produce (Vsn , Topic , Partition , Batch , Opts , make_ref ()).
267+
268+ % % @doc Help function to construct a produce request with a specified request reference.
264269% % By default, it constructs a non-transactional produce request.
265270% % `Batch' arg can be be a `[map()]' like `[#{key => Key, value => Value, ts => Ts}]'.
266271% % Current system time will be taken if `ts' is missing in batch input.
@@ -274,8 +279,8 @@ produce(Vsn, Topic, Partition, Batch) ->
274279% % monotonically increasing, with one sequence number per topic-partition.
275280% % - `txn_ctx' (which is of spec `kpro:txn_ctx()') must exist in `Opts'
276281-spec produce (vsn (), topic (), partition (),
277- binary () | batch_input () | {magic_v2 , non_neg_integer (), iolist ()}, produce_opts ()) -> req ().
278- produce (Vsn , Topic , Partition , Batch , Opts ) ->
282+ binary () | batch_input () | {magic_v2 , non_neg_integer (), iolist ()}, produce_opts (), kpro : req_ref () ) -> req ().
283+ produce (Vsn , Topic , Partition , Batch , Opts , Ref ) ->
279284 ok = assert_known_api_and_vsn (produce , Vsn ),
280285 RequiredAcks = required_acks (maps :get (required_acks , Opts , all_isr )),
281286 Compression = maps :get (compression , Opts , ? no_compression ),
@@ -313,7 +318,7 @@ produce(Vsn, Topic, Partition, Batch, Opts) ->
313318 # kpro_req { api = produce
314319 , vsn = Vsn
315320 , msg = Msg
316- , ref = make_ref ()
321+ , ref = Ref
317322 , no_ack = RequiredAcks =:= 0
318323 }.
319324
@@ -434,11 +439,17 @@ alter_configs(Vsn, Resources, Opts) ->
434439% % @doc Help function to make a request body.
435440-spec make (api (), vsn (), struct ()) -> req ().
436441make (API , Vsn , Fields ) ->
442+ make (API , Vsn , Fields , make_ref ()).
443+
444+ % % @doc Help function to make a request body with provided reference or process alias.
445+ % % The refreence can be an alias to receive response this request.
446+ -spec make (api (), vsn (), struct (), reference ()| {alias , reference ()}) -> req ().
447+ make (API , Vsn , Fields , Ref ) ->
437448 ok = assert_known_api_and_vsn (API , Vsn ),
438449 # kpro_req { api = API
439450 , vsn = Vsn
440451 , msg = encode_struct (API , Vsn , Fields )
441- , ref = make_ref ()
452+ , ref = Ref
442453 }.
443454
444455% % @doc Encode a request to bytes that can be sent on wire.
0 commit comments