Avro Producer and Consumer
These examples produce and consume messages from the supplier
topic. The producer example produces random suppliers.
- kafka producer and consumer example
- kafka consumer settings
- kafka producer settings
- avro project location: kafka-avro
- project location: kafka-clients
⚠️ Run these commands inside the root folder.
Create an alias for kafka-clients
:
alias kafka-clients="$PWD/kafka-clients/build/install/kafka-clients/bin/kafka-clients "
To permanently add the alias to your shell (~/.bashrc
or ~/.zshrc
file):
echo "alias kafka-clients='$PWD/kafka-clients/build/install/kafka-clients/bin/kafka-clients '" >> ~/.zshrc
Create a topic:
kafka-cli kafka-topics --create --bootstrap-server kafka1:9092 \
--replication-factor 3 \
--partitions 3 \
--topic kafka-clients.suppliers
Install the app:
./gradlew kafka-clients:install
kafka-clients
Run clients:
kafka-clients producer 100
kafka-clients consumer
For creating a AVRO schema, you can use the following command (development purposes):
./gradlew kafka-avro:build
Avro Schema
suppliers-v1.avsc
{
"type": "record",
"name": "Supplier",
"namespace": "kafka.sandbox.avro",
"version": "1",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "country",
"type": "string"
}
]
}