rpk topic produce

Produce records to a topic.

Producing records reads from STDIN, parses input according to --format, and produce records to Redpanda. The input formatter understands a wide variety of formats.

Parsing input operates on either sizes or on delimiters, both of which can be specified in the same formatting options. If using sizes to specify something, the size must come before what it is specifying. Delimiters match on an exact text basis. This command will quit with an error if any input fails to match your specified format.


Formatting is based on percent escapes and modifiers. Slashes can be used for common escapes:

Escape Description






Carriage returns




Hex encoded characters

The percent encodings are represented like this:

Percent encoding Description




Topic length




Key length




Value length


Begin the header specification


Number of headers






Leader epoch


Timestamp (formatting described below)


Producer ID


Producer epoch


Partition log start offset


Partition last stable offset


Partition high watermark


Record attributes (formatting described below)


Percent sign


Left brace


Right brace


Number of records formatted


Text and numbers can be formatted in many different ways, and the default format can be changed within brace modifiers. %v prints a value, while %v{hex} prints the value hex encoded. %T prints the length of a topic in ASCII, while %T{big8} prints the length of the topic as an eight byte big endian.

All modifiers go within braces following a percent-escape.


Formatting number values can have the following modifiers:

Format Description


Print the number as ASCII (default)


Sixteen hex characters


Eight hex characters


Four hex characters


Two hex characters


One hex character


Eight byte big endian number


Four byte big endian number


Two byte big endian number


Alias for byte


Eight byte little endian number


Four byte little endian number


Two byte little endian number


Alias for byte


One byte number


true if the number is non-zero, false if the number is zero

All numbers are truncated as necessary per the modifier. Printing %V{byte} for a length 256 value prints a single null, whereas printing %V{big8} prints the bytes 1 and 0.

When writing number sizes, the size corresponds to the size of the raw values, not the size of encoded values. %T% t{hex} for the topic foo prints 3 666f6f, not 6 666f6f.


By default, the timestamp field is printed as a millisecond number value. In addition to the number modifiers above, timestamps can be printed with either Go formatting:


Or strftime formatting:


An arbitrary amount of brackets (or braces, or # symbols) can wrap your date formatting:

%d{strftime=== [%F] ===}

This prints [YYYY-MM-DD], while the surrounding three # on each side are used to wrap the formatting.

For more information on Go time formatting, see the Go documentation.

For more information on strftime formatting, run man strftime.

Schema registry

Records can be encoded using a specified schema from our schema registry. Use the --schema-id or --schema-key-id flags to define the schema ID, rpk will retrieve the schemas and encode the record accordingly.

Additionally, utilizing topic in the mentioned flags allows for the use of the Topic Name Strategy. This strategy identifies a schema subject name based on the topic itself. For example:

Produce to foo, encode using the latest schema in the subject foo-value:

rpk topic produce foo --schema-id=topic

For protobuf schemas, you can specify the fully qualified name of the message you want the record to be encoded with. Use the schema-type flag or schema-key-type. If the schema contains only one message, specifying the message name is unnecessary. For example:

Produce to foo, using schema ID 1, message FQN Person.Name:

rpk topic produce foo --schema-id 1 --schema-type Person.Name


In the below examples, we can parse many records at once. The produce command reads input and tokenizes based on your specified format. Every time the format is completely matched, a record is produced and parsing begins anew.

  • A key and value, separated by a space and ending in newline: -f '%k %v\n'

  • A four byte topic, four byte key, and four byte value: -f '%T{4}%K{4}%V{4}%t%k%v'

  • A value to a specific partition, if using a non-negative --partition flag: -f '%p %v\n'

  • A big-endian uint16 key size, the text " foo ", and then that key: -f '%K{big16} foo %k'

  • A value that can be two or three characters followed by a newline: -f '%v{re#...?#}\n'

  • A key and a json value, separated by a space: -f '%k %v{json}'


Producing requires a topic to produce to. The topic can be specified either directly on as an argument, or in the input text through %t. A parsed topic takes precedence over the default passed in topic. If no topic is specified directly and no topic is parsed, this command will quit with an error.

The input format can parse partitions to produce directly to with %p. Doing so requires specifying a non-negative --partition flag. Any parsed partition takes precedence over the --partition flag; specifying the flag is the main requirement for being able to directly control which partition to produce to.

You can also specify an output format to write when a record is produced successfully. The output format follows the same formatting rules as the topic consume command. See that command’s help text for a detailed description.


rpk topic produce [TOPIC] [flags]


Value Type Description



Number of acks required for producing (-1=all, 0=none, 1=leader) (default -1).



Auto-create non-existent topics; requires auto_create_topics_enabled on the broker.

-z, --compression


Compression to use for producing batches (none, gzip, snappy, lz4, zstd) (default "snappy").



Per-record delivery timeout, if non-zero, min 1s.

-f, --format


Input record format (default "%v\n").

-H, --header


Headers in format key:value to add to each record (repeatable).

-h, --help


Help for produce.

-k, --key


A fixed key to use for each record (parsed input keys take precedence).



If non-negative, maximum size of a record batch before compression (default -1).

-o, --output-format


what to write to stdout when a record is successfully produced (default "Produced to partition %p at offset %o with timestamp %d.\n").

-p, --partition


Partition to directly produce to, if non-negative (also allows %p parsing to set partitions) (default -1).



Schema ID to encode the record value with, use topic for TopicName strategy.



Schema ID to encode the record key with, use topic for TopicName strategy.



Name of the protobuf message type to be used to encode the record key using schema registry.



Name of the protobuf message type to be used to encode the record value using schema registry.

-Z, --tombstone


Produce empty values as tombstones.



Redpanda or rpk config file; default search paths are /var/lib/redpanda/.config/rpk/rpk.yaml, $PWD/redpanda.yaml, and /etc/redpanda/redpanda.yaml.

-X, --config-opt


Override rpk configuration settings. See rpk -X or execute rpk -X help for inline detail or rpk -X list for terser detail.



Profile to use. See rpk profile for more details.

-v, --verbose


Enable verbose logging.