Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

90 строки
3.3 KiB

  1. #!/bin/bash
  2. set -euo pipefail
  3. # Retention: messages older than 2 days are deleted (172800000 ms = 2 days)
  4. RETENTION_MS=172800000
  5. KAFKA_BOOTSTRAP_SERVER="kafka:29092"
  6. wait_for_topic() {
  7. local topic="$1"
  8. # Topic metadata can take a moment to become available after creation.
  9. for i in $(seq 1 30); do
  10. if /opt/kafka/bin/kafka-topics.sh \
  11. --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  12. --topic "$topic" \
  13. --describe >/dev/null 2>&1; then
  14. return 0
  15. fi
  16. sleep 1
  17. done
  18. echo "timed out waiting for topic '$topic' to be available" >&2
  19. return 1
  20. }
  21. # create topic rawbeacons
  22. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  23. --create --if-not-exists --topic rawbeacons \
  24. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  25. # create topic apibeacons
  26. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  27. --create --if-not-exists --topic apibeacons \
  28. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  29. # create topic alertBeacons
  30. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  31. --create --if-not-exists --topic alertbeacons \
  32. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  33. # create topic locevents
  34. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  35. --create --if-not-exists --topic locevents \
  36. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  37. # create topic settings
  38. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  39. --create --if-not-exists --topic settings \
  40. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  41. # create topic alert
  42. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  43. --create --if-not-exists --topic alert \
  44. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  45. # create topic healthlocation
  46. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  47. --create --if-not-exists --topic healthlocation \
  48. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  49. # create topic healthdecoder
  50. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  51. --create --if-not-exists --topic healthdecoder \
  52. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  53. # create topic healthbridge
  54. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  55. --create --if-not-exists --topic healthbridge \
  56. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  57. # create topic parser (server writes parser config, decoder reads it)
  58. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  59. --create --if-not-exists --topic parser \
  60. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  61. # create topic mqtt (bridge reads/writes MQTT event payloads)
  62. /opt/kafka/bin/kafka-topics.sh --bootstrap-server "$KAFKA_BOOTSTRAP_SERVER" \
  63. --create --if-not-exists --topic mqtt \
  64. --partitions 1 --replication-factor 1 --config retention.ms=$RETENTION_MS
  65. wait_for_topic rawbeacons
  66. wait_for_topic apibeacons
  67. wait_for_topic alertbeacons
  68. wait_for_topic locevents
  69. wait_for_topic settings
  70. wait_for_topic alert
  71. wait_for_topic healthlocation
  72. wait_for_topic healthdecoder
  73. wait_for_topic healthbridge
  74. wait_for_topic parser
  75. wait_for_topic mqtt