@@ -55,8 +55,8 @@ def __init__(self, tp, records, buffer):
55
55
def record_count (self ):
56
56
return self .records .next_offset ()
57
57
58
- def try_append (self , timestamp_ms , key , value ):
59
- metadata = self .records .append (timestamp_ms , key , value )
58
+ def try_append (self , timestamp_ms , key , value , headers ):
59
+ metadata = self .records .append (timestamp_ms , key , value , headers )
60
60
if metadata is None :
61
61
return None
62
62
@@ -65,7 +65,8 @@ def try_append(self, timestamp_ms, key, value):
65
65
future = FutureRecordMetadata (self .produce_future , metadata .offset ,
66
66
metadata .timestamp , metadata .crc ,
67
67
len (key ) if key is not None else - 1 ,
68
- len (value ) if value is not None else - 1 )
68
+ len (value ) if value is not None else - 1 ,
69
+ sum (len (h_key .encode ("utf-8" )) + len (h_val ) for h_key , h_val in headers ) if headers else - 1 )
69
70
return future
70
71
71
72
def done (self , base_offset = None , timestamp_ms = None , exception = None ):
@@ -196,7 +197,7 @@ def __init__(self, **configs):
196
197
self .muted = set ()
197
198
self ._drain_index = 0
198
199
199
- def append (self , tp , timestamp_ms , key , value , max_time_to_block_ms ,
200
+ def append (self , tp , timestamp_ms , key , value , headers , max_time_to_block_ms ,
200
201
estimated_size = 0 ):
201
202
"""Add a record to the accumulator, return the append result.
202
203
@@ -209,6 +210,7 @@ def append(self, tp, timestamp_ms, key, value, max_time_to_block_ms,
209
210
timestamp_ms (int): The timestamp of the record (epoch ms)
210
211
key (bytes): The key for the record
211
212
value (bytes): The value for the record
213
+ headers (List[Tuple[str, bytes]]): The header fields for the record
212
214
max_time_to_block_ms (int): The maximum time in milliseconds to
213
215
block for buffer memory to be available
214
216
@@ -231,7 +233,7 @@ def append(self, tp, timestamp_ms, key, value, max_time_to_block_ms,
231
233
dq = self ._batches [tp ]
232
234
if dq :
233
235
last = dq [- 1 ]
234
- future = last .try_append (timestamp_ms , key , value )
236
+ future = last .try_append (timestamp_ms , key , value , headers )
235
237
if future is not None :
236
238
batch_is_full = len (dq ) > 1 or last .records .is_full ()
237
239
return future , batch_is_full , False
@@ -246,7 +248,7 @@ def append(self, tp, timestamp_ms, key, value, max_time_to_block_ms,
246
248
247
249
if dq :
248
250
last = dq [- 1 ]
249
- future = last .try_append (timestamp_ms , key , value )
251
+ future = last .try_append (timestamp_ms , key , value , headers )
250
252
if future is not None :
251
253
# Somebody else found us a batch, return the one we
252
254
# waited for! Hopefully this doesn't happen often...
@@ -261,7 +263,7 @@ def append(self, tp, timestamp_ms, key, value, max_time_to_block_ms,
261
263
)
262
264
263
265
batch = ProducerBatch (tp , records , buf )
264
- future = batch .try_append (timestamp_ms , key , value )
266
+ future = batch .try_append (timestamp_ms , key , value , headers )
265
267
if not future :
266
268
raise Exception ()
267
269
0 commit comments