127127 , inflight_calls := non_neg_integer ()
128128 , topic := topic ()
129129 , calls := ? EMPTY | calls ()
130+ , sender => pid ()
130131 }.
131132
132133% % @doc Start a per-partition producer worker.
@@ -231,7 +232,8 @@ send_sync(Pid, Batch0, Timeout) ->
231232init (#{client_id := ClientId , topic := Topic , partition := Partition } = St ) ->
232233 erlang :process_flag (trap_exit , true ),
233234 ok = set_process_label (ClientId , Topic , Partition ),
234- {ok , St , {continue , do_init }}.
235+ {ok , Sender } = wolff_sender :start_link (self (), ClientId , Topic , Partition ),
236+ {ok , St #{sender => Sender }, {continue , do_init }}.
235237
236238do_init (#{client_id := ClientId ,
237239 topic := Topic ,
@@ -423,10 +425,12 @@ use_defaults(Config, [{K, V} | Rest]) ->
423425 false -> use_defaults (Config #{K => V }, Rest )
424426 end .
425427
426- resend_requests (#{q_items := Items } = Sent , St , ? reconnect ) ->
428+ resend_requests (#{q_items := Items , req_ref := {alias , OldRef }} = Sent , St , ? reconnect ) ->
429+ erlang :unalias (OldRef ),
427430 {ok , Ref } = send_request (Items , St ),
428431 [Sent #{req_ref := Ref }];
429- resend_requests (#{q_items := Items } = Sent , St , ? message_too_large ) ->
432+ resend_requests (#{q_items := Items , req_ref := {alias , OldRef }} = Sent , St , ? message_too_large ) ->
433+ erlang :unalias (OldRef ),
430434 Refs = lists :map (fun (Item ) -> {ok , Ref } = send_request ([Item ], St ), Ref end , Items ),
431435 #{attempts := Attempts , q_ack_ref := Q_AckRef } = Sent ,
432436 make_sent_items_list (Items , Refs , Attempts , Q_AckRef ).
@@ -445,25 +449,25 @@ make_sent_items_list([Item | Items], [Ref | Refs], Attempts, Q_AckRef) ->
445449 attempts => Attempts
446450 } | make_sent_items_list (Items , Refs , Attempts , Q_AckRef )].
447451
448- send_request (QueueItems , #{conn := Conn } = St ) ->
449- # kpro_req {ref = Ref } = Req = make_request (QueueItems , St ),
450- ok = request_async (Conn , Req ),
451- {ok , Ref }.
452-
453- make_request (QueueItems ,
452+ send_request (QueueItems ,
454453 #{config := #{required_acks := RequiredAcks ,
455454 ack_timeout := AckTimeout ,
456455 compression := Compression
457456 },
458457 produce_api_vsn := Vsn ,
459458 topic := Topic ,
460- partition := Partition }) ->
459+ partition := Partition ,
460+ conn := Conn ,
461+ sender := Sender
462+ }) ->
461463 Batch = get_batch_from_queue_items (QueueItems ),
462- kpro_req_lib :produce (Vsn , Topic , Partition , Batch ,
463- #{ack_timeout => AckTimeout ,
464- required_acks => RequiredAcks ,
465- compression => Compression
466- }).
464+ Opts = #{ack_timeout => AckTimeout ,
465+ required_acks => RequiredAcks ,
466+ compression => Compression
467+ },
468+ Ref = {alias , erlang :alias ([reply ])},
469+ ok = wolff_sender :do (Sender , Conn , Ref , Vsn , Topic , Partition , Batch , Opts ),
470+ {ok , Ref }.
467471
468472resend_sent_reqs (#{sent_reqs := SentReqs ,
469473 config := Config
@@ -874,9 +878,6 @@ varint_bytes(N) -> vb(zz(N)).
874878-compile ({inline , zz / 1 }).
875879zz (I ) -> (I bsl 1 ) bxor (I bsr 63 ).
876880
877- request_async (Conn , Req ) when is_pid (Conn ) ->
878- ok = kpro :send (Conn , Req ).
879-
880881% % collect send calls which are already sent to mailbox,
881882% % the collection is size-limited by the max_linger_bytes config.
882883collect_send_calls (Call , Bytes , ? EMPTY , Max ) ->
0 commit comments