Interface KafkaRecordBuilder
-
@DoNotImplement public interface KafkaRecordBuilder
The KafkaRecordBuilder enables the creation ofKafkaRecords via its fluent API.All data in a
KafkaRecordexcept 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 KafkaRecordbuild()Create a newKafkaRecordfrom the current state of this builder.@NotNull KafkaRecordBuilderheader(@NotNull String key, byte @NotNull [] value)Add a header to the Kafka record.@NotNull KafkaRecordBuilderheader(@NotNull String key, @NotNull String value)Add a header to the Kafka record.@NotNull KafkaRecordBuilderheader(@NotNull String key, @NotNull String value, @NotNull Charset charset)Add a header to the Kafka record.@NotNull KafkaRecordBuilderheader(@NotNull String key, @NotNull ByteBuffer value)Add a header to the Kafka record.@NotNull KafkaRecordBuilderkey(byte @NotNull [] key)Set the key of the Kafka record.@NotNull KafkaRecordBuilderkey(@NotNull String key)Set the key of the Kafka record.@NotNull KafkaRecordBuilderkey(@NotNull String key, @NotNull Charset charset)Set the key of the Kafka record.@NotNull KafkaRecordBuilderkey(@NotNull ByteBuffer key)Set the key of the Kafka record.@NotNull KafkaRecordBuilderpartition(int partition)Set the partition number of the Kafka record.@NotNull KafkaRecordBuildertimestamp(long timestamp)Set the timestamp of the Kafka record.@NotNull KafkaRecordBuildertopic(@NotNull String topic)Set the topic of the Kafka record.@NotNull KafkaRecordBuildervalue(byte @NotNull [] value)Set the value of the Kafka record.@NotNull KafkaRecordBuildervalue(@NotNull String value)Set the value of the Kafka record.@NotNull KafkaRecordBuildervalue(@NotNull String value, @NotNull Charset charset)Set the value of the Kafka record.@NotNull KafkaRecordBuildervalue(@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 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_8is 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- theCharsetused 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_8is 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- theCharsetused 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_8is 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- theCharsetused 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 newKafkaRecordfrom the current state of this builder. The builder can be reused afterwards.- Returns:
- a new
KafkaRecordcontaining a snapshot of the current state of this builder. - Throws:
NullPointerException- if the topic was not set.- Since:
- 4.4.0
-
-