Interface KafkaRecordBuilder
@DoNotImplement public interface KafkaRecordBuilder
The KafkaRecordBuilder enables the creation of
KafkaRecord
s via its fluent API.
All data in a KafkaRecord
except the topic is optional. Ensure that you set a topic via the topic(String)
method before you call build()
.
The internal state of this interface can only be changed via its methods. All arguments, that have mutable data types, are deep copied before the setting method returns.
- Since:
- 4.4.0
-
Method Summary
Modifier and Type Method Description @NotNull KafkaRecord
build()
Create a newKafkaRecord
from the current state of this builder.@NotNull KafkaRecordBuilder
header(@NotNull String key, byte @NotNull [] value)
Add a header to the Kafka record.@NotNull KafkaRecordBuilder
header(@NotNull String key, @NotNull String value)
Add a header to the Kafka record.@NotNull KafkaRecordBuilder
header(@NotNull String key, @NotNull String value, @NotNull Charset charset)
Add a header to the Kafka record.@NotNull KafkaRecordBuilder
header(@NotNull String key, @NotNull ByteBuffer value)
Add a header to the Kafka record.@NotNull KafkaRecordBuilder
key(byte @NotNull [] key)
Set the key of the Kafka record.@NotNull KafkaRecordBuilder
key(@NotNull String key)
Set the key of the Kafka record.@NotNull KafkaRecordBuilder
key(@NotNull String key, @NotNull Charset charset)
Set the key of the Kafka record.@NotNull KafkaRecordBuilder
key(@NotNull ByteBuffer key)
Set the key of the Kafka record.@NotNull KafkaRecordBuilder
partition(int partition)
Set the partition number of the Kafka record.@NotNull KafkaRecordBuilder
timestamp(long timestamp)
Set the timestamp of the Kafka record.@NotNull KafkaRecordBuilder
topic(@NotNull String topic)
Set the topic of the Kafka record.@NotNull KafkaRecordBuilder
value(byte @NotNull [] value)
Set the value of the Kafka record.@NotNull KafkaRecordBuilder
value(@NotNull String value)
Set the value of the Kafka record.@NotNull KafkaRecordBuilder
value(@NotNull String value, @NotNull Charset charset)
Set the value of the Kafka record.@NotNull KafkaRecordBuilder
value(@NotNull ByteBuffer value)
Set the value of the Kafka record.
-
Method Details
-
topic
Set the topic of the Kafka record.This is required to successfully build a
KafkaRecord
.- Parameters:
topic
- the name of the topic.- Returns:
- this builder
- Throws:
IllegalArgumentException
- if topic is not a valid name for a Kafka topic- Since:
- 4.4.0
-
key
Set the key of the Kafka record.- Parameters:
key
- the value of the key.- Returns:
- this builder
- Since:
- 4.4.0
-
key
Set the key of the Kafka record.- Parameters:
key
- the value of the key.- Returns:
- this builder
- Since:
- 4.4.0
-
key
Set the key of the Kafka record.- Parameters:
key
- the value of the key.StandardCharsets.UTF_8
is used for encoding.- Returns:
- this builder
- Since:
- 4.4.0
-
key
@NotNull @NotNull KafkaRecordBuilder key(@NotNull @NotNull String key, @NotNull @NotNull Charset charset)Set the key of the Kafka record.- Parameters:
key
- the value of the key.charset
- theCharset
used for encoding.- Returns:
- this builder
- Since:
- 4.4.0
-
value
Set the value of the Kafka record.- Parameters:
value
- the value of the Kafka value.- Returns:
- this builder
- Since:
- 4.4.0
-
value
Set the value of the Kafka record.- Parameters:
value
- the value of the Kafka value.- Returns:
- this builder
- Since:
- 4.4.0
-
value
Set the value of the Kafka record.- Parameters:
value
- the value of the Kafka value.StandardCharsets.UTF_8
is used for encoding.- Returns:
- this builder
- Since:
- 4.4.0
-
value
@NotNull @NotNull KafkaRecordBuilder value(@NotNull @NotNull String value, @NotNull @NotNull Charset charset)Set the value of the Kafka record.- Parameters:
value
- the value of the Kafka value.charset
- theCharset
used for encoding.- Returns:
- this builder
- Since:
- 4.4.0
-
header
@NotNull @NotNull KafkaRecordBuilder header(@NotNull @NotNull String key, @NotNull @NotNull ByteBuffer value)Add a header to the Kafka record.- Parameters:
key
- the key of the header.value
- the value of the header.- Returns:
- this builder
- Since:
- 4.4.0
-
header
Add a header to the Kafka record.- Parameters:
key
- the key of the header.value
- the value of the header.- Returns:
- this builder
- Since:
- 4.4.0
-
header
@NotNull @NotNull KafkaRecordBuilder header(@NotNull @NotNull String key, @NotNull @NotNull String value)Add a header to the Kafka record.- Parameters:
key
- the key of the header.value
- the value of the header.StandardCharsets.UTF_8
is used for encoding.- Returns:
- this builder
- Since:
- 4.4.0
-
header
@NotNull @NotNull KafkaRecordBuilder header(@NotNull @NotNull String key, @NotNull @NotNull String value, @NotNull @NotNull Charset charset)Add a header to the Kafka record.- Parameters:
key
- the key of the header.value
- the value of the header.charset
- theCharset
used for encoding thevalue
.- Returns:
- this builder
- Since:
- 4.4.0
-
timestamp
Set the timestamp of the Kafka record.- Parameters:
timestamp
- the value of the Kafka timestamp, in milliseconds since UNIX epoch.- Returns:
- this builder
- Since:
- 4.4.0
-
partition
Set the partition number of the Kafka record.- Parameters:
partition
- the value of the Kafka partition number.- Returns:
- this builder
- Since:
- 4.4.0
-
build
Create a newKafkaRecord
from the current state of this builder. The builder can be reused afterwards.- Returns:
- a new
KafkaRecord
containing a snapshot of the current state of this builder. - Throws:
NullPointerException
- if the topic was not set.- Since:
- 4.4.0
-