Skip to content

Instantly share code, notes, and snippets.

@IanVaughan
Created November 1, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanVaughan/e35d1ef24c2df7e9445943b4b489a8ac to your computer and use it in GitHub Desktop.
Save IanVaughan/e35d1ef24c2df7e9445943b4b489a8ac to your computer and use it in GitHub Desktop.
ccloud kafka topic create --partitions 1 test-topic

ccloud kafka topic produce test-topic --value-format avro --schema /path/to/schema.json
{"myField":"test","myField2":1}
{"myField":"foo","myField2":2}

Finish Getting Started with Schema Registry Produce and consume messages with schemas using the Confluent Schema Registry

  1. Log in to your cluster using the ccloud login command with the cluster URL specified.
ccloud login
  1. Set the Confluent Cloud environment and cluster
ccloud environment use env-xxx
ccloud kafka cluster use lkc-xxx
  1. If you don't have a Kafka API key, generate one and set it to use (replacing <API_KEY> with generated key) from the CLI
ccloud api-key create --resource lkc-xxx
ccloud api-key use <API_KEY> --resource lkc-xxx
  1. Produce a message using your schema (replace <PATH_TO_SCHEMA_FILE> with your local path to the schema file)
ccloud kafka topic produce orders --value-format jsonschema --schema <PATH_TO_SCHEMA_FILE>

Enter the Schema Registry API key and secret created previously. Then, produce a message formatted accordingly to the schema created for the topic "orders".

{"orderId":2122453, "orderTime": 1607641868, "orderAddress":"899 W Evelyn Ave, Mountain View, CA 94041"}
  1. Consume the message you just produced by retrieving the schema from the Schema Registry (ctrl+C to stop the produce command from previous step or open a new terminal) ccloud kafka topic consume orders --value-format jsonschema --from-beginning

Kafka

bootstrap.servers=pkc-xxx.europe-west1.gcp.confluent.cloud:9092
security.protocol=SASL_SSL
sasl.mechanisms=PLAIN
sasl.username=xxx
sasl.password=xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment