Important

You are viewing documentation for an older version of Confluent Platform. For the latest, click here.

confluent produce

Description

Produce data to topics. By default this command produces non-Avro data to the Apache Kafka® cluster on the localhost.

For this command to work, you must configure the PATH environment variable to point to the Confluent Platform bin directory.

For reference on how to use Confluent CLI to consume from a topic, see confluent consume.

Usage

confluent produce <topicname> [--value-format avro --property value.schema=<schema>] [--cloud] [other optional args]

Tip

For usage information, enter confluent help produce.

Required Arguments

Name, shorthand Default Description
<topicname>   Kafka topic to produce messages to

Optional Arguments

Here are some common optional arguments. For a full list of optional arguments:

confluent help produce
Name, shorthand Default Description
--value-format avro   Specify the topic data as Avro data.
--property value.schema=<schema>   Provide the schema for the Avro data.
--cloud   Connect to Confluent Cloud using configuration file at default location $HOME/.ccloud/config
--config <filename>   Specify an alternate configuration file
--broker-list localhost:9092 Kafka brokers to connect to.

Examples

  • Produce Avro data to a topic called mytopic1 on a development Kafka cluster on localhost. Assumes Confluent Schema Registry is listening at http://localhost:8081.

    confluent produce mytopic1 --value-format avro --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'
    
  • Produce non-Avro data to a topic called mytopic2 on a development Kafka cluster on localhost:

    confluent produce mytopic2
    
  • Produce non-Avro data to a topic called mytopic3 in Confluent Cloud (assumes you have initialized your Confluent Cloud configuration with Confluent Cloud CLI. Assumes topic has already been created.

    confluent produce mytopic3 --cloud
    
  • Produce messages with keys and non-Avro values to a topic called mytopic4 in Confluent Cloud, using a user-specified Confluent Cloud configuration file at /tmp/config. Assumes topic has already been created.

    confluent produce mytopic4 --cloud --config /tmp/config --property parse.key=true --property key.separator=,
    
  • Produce Avro data to a topic called mytopic5 in Confluent Cloud. Assumes topic has already been created, and Confluent Schema Registry is listening at http://localhost:8081

    confluent produce mytopic5 --cloud --value-format avro --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}' --property schema.registry.url=http://localhost:8081