Kafka
JR has been built with Apache Kafka in mind since the inception, so the Kafka support is pretty advanced.
Writing data to Apache Kafka
Just use the --output kafka
(which defaults to console
) flag and --topic
flag to indicate the topic name:
jr run net_device -n 5 -f 500ms -o kafka -t test
If you don’t specify a key, ta null key will be used for each record.
Using --key
you can use a template for the key, to be embedded directly in the command:
For example:
jr run -k '{{key "KEY" 20}}' -f 1s -d 10s net_device -o kafka -t test
Another example:
jr run -k '{{randoms "ONE|TWO|THREE"}}' -f 1s -d 10s net_device -o kafka -t test
Autocreate topics
Topics autocreation is disabled in Confluent Cloud.
If you are really lazy you can use the -a
option, so JR will create the topic for you.
jr run -a -k '{{randoms "ONE|TWO|THREE"}}' -f 1s -d 10s net_device -o kafka -t mynewtopic
Alternatively, you can also create it explicitly from JR:
jr createTopic mynewtopic
If you want to specify number of partitions and replication Factor you can use the -p
and -r
flags:
jr createTopic mynewtopic -p 10 -r 2