هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
Apache Kafka is a distributed event log: producers write records to topics; topics are split into partitions and copied to several brokers (replication). Consumers in a consumer group share the partitions and remember their offset. Kafka carries logs, metrics, clicks, orders and change-data-capture between systems. Kafka 4 runs without ZooKeeper (KRaft). The tools are shell scripts in bin/ (kafka-topics.sh …); some packages drop the .sh.
Managed versions: Azure Event Hubs (Kafka API), Confluent Cloud, AWS MSK. On Kubernetes: the Strimzi operator.
طريقة الكتابة
kafka-topics.sh --bootstrap-server HOST:9092 --create|--list|--describe|--alter|--delete [--topic NAME]
kafka-console-producer.sh / kafka-console-consumer.sh --bootstrap-server HOST:9092 --topic NAMEالأجزاء الرئيسية
Tools
kafka-topics.sh- Create, list, describe topics.
kafka-console-producer.sh- Write messages from the terminal.
kafka-console-consumer.sh- Read messages.
kafka-consumer-groups.sh- Groups, offsets, lag.
kafka-configs.sh- Topic and broker settings (retention).
kafka-acls.sh- Access control lists.
kafka-storage.sh- Format storage for KRaft.
الخيارات 7
الأكثر استخدامًا
Flags
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 10
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Run Kafka (KRaft) in a container for a lab
podman run -d --name kafka -p 127.0.0.1:9092:9092 docker.io/apache/kafka:3.8.12Create and describe a topic
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic shop.orders --partitions 6 --replication-factor 1 kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic shop.orders3Send and read test messages
echo '{"id": 1, "total": 49.90}' | kafka-console-producer.sh --bootstrap-server localhost:9092 --topic shop.orders kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic shop.orders --from-beginning --max-messages 54Check consumer lag (are consumers behind?)
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group invoice-service5Reset a group to re-read a topic
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group invoice-service --topic shop.orders --reset-offsets --to-earliest --execute6Set retention to 7 days
kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name shop.orders --add-config retention.ms=6048000007Connect with TLS and SASL
cat client.properties security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="shop" password="Example-Only"; ssl.truststore.location=/etc/kafka/truststore.jks kafka-topics.sh --bootstrap-server kafka.lab.local:9093 --command-config client.properties --list8Allow a user to read one topic (ACL)
kafka-acls.sh --bootstrap-server kafka.lab.local:9093 --command-config admin.properties --add --allow-principal User:invoice --operation Read --topic shop.orders --group invoice-service9List all topics
kafka-topics.sh --bootstrap-server localhost:9092 --list10Strimzi on Kubernetes: a topic as YAML
cat topic.yaml apiVersion: kafka.strimzi.io/v1beta2 kind: KafkaTopic metadata: { name: shop.orders, labels: { strimzi.io/cluster: lab } } spec: { partitions: 6, replicas: 3 }
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- You can add partitions but never remove them; plan the count (and keys change partitions when you add).
- Without TLS and SASL anyone on the network can read and write all topics.
- Watch consumer lag — growing lag means data waits and may expire.
الملفات
config/server.properties- Broker settings.
client.properties- Client TLS/SASL settings (keep private).
نصائح للحفظ
- Name topics
domain.entity[.event](shop.orders.created) and keep the schema in a registry.
رموز الخروج
0 | Success. |
1 | Error. |