Interface KafkaRecordBuilder
-
@DoNotImplement public interface KafkaRecordBuilder
The KafkaRecordBuilder enables the creation ofKafkaRecord
s via its fluent API.All data in a
KafkaRecord
except the topic is optional. Ensure that you set a topic via thetopic(String)
method before you callbuild()
.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
All Methods Instance Methods Abstract Methods 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 Detail
-
topic
@NotNull @NotNull KafkaRecordBuilder topic(@NotNull @NotNull String 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 the topic is not a valid name for a Kafka topic.- Since:
- 4.4.0
-
key
@NotNull @NotNull KafkaRecordBuilder key(@NotNull @NotNull ByteBuffer key)
Set the key of the Kafka record.- Parameters:
key
- the value of the key.- Returns:
- This builder.
- Since:
- 4.4.0
-
key
@NotNull @NotNull KafkaRecordBuilder key(byte @NotNull [] key)
Set the key of the Kafka record.- Parameters:
key
- The value of the key.- Returns:
- This builder.
- Since:
- 4.4.0
-
key
@NotNull @NotNull KafkaRecordBuilder key(@NotNull @NotNull String 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
@NotNull @NotNull KafkaRecordBuilder value(@NotNull @NotNull ByteBuffer value)
Set the value of the Kafka record.- Parameters:
value
- The value of the Kafka value.- Returns:
- This builder.
- Since:
- 4.4.0
-
value
@NotNull @NotNull KafkaRecordBuilder value(byte @NotNull [] value)
Set the value of the Kafka record.- Parameters:
value
- The value of the Kafka value.- Returns:
- This builder.
- Since:
- 4.4.0
-
value
@NotNull @NotNull KafkaRecordBuilder value(@NotNull @NotNull String 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
@NotNull @NotNull KafkaRecordBuilder header(@NotNull @NotNull String key, byte @NotNull [] 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
@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
@NotNull @NotNull KafkaRecordBuilder timestamp(long 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
@NotNull @NotNull KafkaRecordBuilder partition(int 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
@NotNull @NotNull KafkaRecord 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
-
-