Share this page

# LrKafkaProducer.newRecord

A fluent Builder pattern API for constructing producer records.

Note: This API function is supported from version 26.3.

`public RecordBuilder newRecord(String topic)`

## Methods

Method | Type | Description
--- | --- | ---
.withValue(value) | Required builder method | Sets the record value.
.withKey(key) | Optional builder method | Sets the record key.
.withHeader(name, value) | Optional builder method | Adds a message header; repeatable for multiple headers.
.withPartition(partition) | Optional builder method | Pins the record to a specific partition.
.withTimestamp(timestamp) | Optional builder method | Sets the record timestamp in milliseconds.
.build() | Terminal method | Constructs the final ProducerRecord.

## Return Values

This function returns the ProducerRecord for the given topic.

## General information

Both withPartition() and withTimestamp() are supported by the Builder, but are intentionally omitted during the code generation phase:

- Partition. The original partition is specific to the cluster and topic configuration at recording time. Hard-coding it would make the script fail or produce skewed results, if the target cluster has a different number of partitions, or if key-based partitioning applies during replay. Omitting it lets Kafka assign partitions naturally during replay.

- Timestamp. The recorded timestamp reflects the exact moment the message was produced during the recording session. Replaying a script with those timestamps would inject historical timestamps into the topic rather than current ones.

Both can be added manually to the generated script, if the test scenario specifically requires controlling partition assignment or timestamp values.

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: