Skip to content

Commit

Permalink
Fix invalid KafkaMessage type
Browse files Browse the repository at this point in the history
The `size` attribute is only ever present on pre-0.10 `Messages`,
and never on the new `Record`. The field was mistakenly defined as
being non-optional.

Providing a meaningful `size` field for Record is tricky because in
RecordBatch all the records are compressed together, rather than individually
as is the case with the old Message protocol. Therefore you can only
calculate a size for the uncompressed record, which isn't very useful
since you most likely care about the size because you want to understand
the size over the network.
  • Loading branch information
Nevon committed Jun 22, 2022
1 parent a733eaa commit ebd25c2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,16 +631,26 @@ export type Broker = {
}): Promise<any>
}

export type KafkaMessage = {
interface MessageSetEntry {
key: Buffer | null
value: Buffer | null
timestamp: string
attributes: number
offset: string
size: number
}

interface RecordBatchEntry {
key: Buffer | null
value: Buffer | null
timestamp: string
attributes: number
offset: string
headers?: IHeaders
headers: IHeaders
}

export type KafkaMessage = MessageSetEntry | RecordBatchEntry

export interface ProducerRecord {
topic: string
messages: Message[]
Expand Down

0 comments on commit ebd25c2

Please sign in to comment.