You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. #!/bin/bash
  2. kafka_root=${KAFKA_ROOT:-/opt/kafka}
  3. # Generate and insert some messages
  4. OS=$(uname -s)
  5. function initializeTopic {
  6. topic=$1
  7. host=$2
  8. msg_size=$3
  9. batch_size=$4
  10. batch_count=$5
  11. if [ $host == "localhost:9092" ]; then
  12. ${kafka_root}/bin/kafka-topics.sh --create --zookeeper localhost:2181 \
  13. --replication-factor 1 --partitions 1 --topic ${topic}
  14. fi
  15. echo "Generating messages (size: ${msg_size})"
  16. : > /tmp/msgs # Truncate /tmp/msgs
  17. for i in $(seq 1 ${batch_size}); do
  18. if [ $OS == 'Darwin' ]; then
  19. printf %s\\n "$(head -c${msg_size} /dev/urandom | base64)" >> /tmp/msgs
  20. else
  21. printf %s\\n "$(head --bytes=${msg_size} /dev/urandom | base64 --wrap=0)" >> /tmp/msgs
  22. fi
  23. done
  24. echo "Done generating messages"
  25. for i in $(seq 1 ${batch_count}); do
  26. echo "Adding $(wc -l /tmp/msgs) messages to topic ${topic}"
  27. "${kafka_root}/bin/kafka-console-producer.sh" \
  28. --broker-list ${host} --topic ${topic} < /tmp/msgs
  29. done
  30. }
  31. initializeTopic "librdtesting-01" "localhost:9092" "4096" "5000" "2000"