Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to perform basic Kafka operations

Shulou Source: shulou.com Published: 2022-06-01 13:19:05 10月03日 Update

Today, I will talk to you about how to implement the basic operation of Kafka. Many people may not know much about it. In order to let you know more, Xiaobian summarized the following contents for you. I hope you can gain something according to this article.

Topic Topics

When kafka data is persisted, in order to distinguish different business topics, the concept of topic is designed, similar to database name, database has several data tables. Different types of message data are classified according to certain rules, and finally the same type of service data is stored under the same topic.

Create topic automatically

Themes are automatically created with the auto.create.topocs.enable attribute, which defaults to true. When producer item kafk sends a topic that doesn't exist, kafka creates a topic with default configuration coefficients. The default partition values are controlled by num.partitions, and the default replication factor is controlled by default.replication.factor. The specific configuration file is in the current kafka config/server.properties

manually create

The specific command is as follows, the subject name is topic-test, because it is the development environment to build partitions and copy partitions are 1

$ kafka-topics.sh --zookeeper localhost: 2181/kafka --create --topic topic-test --replication-factor 1 --partitions 1Created topic "topic-test".

--topic Definition topic name

--replication-factor defines the number of copies

--partitions Defines the number of partitions

View topic

View all topics

$kafka-topics.sh --list -zookeeper localhost:2181__consumer_offsetstopic-test

View topic details

$kafka-topics.sh--zookeeper localhost:2181 --describe --topic topic-testTopic:test PartitionCount:1 ReplicationFactor:1 Configurations: Topic: test Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Send/receive messages $kafka-console-producer.sh--broker-localhost:9092 --topic topic-test>hello kafka>hello worldkafka-console-consumer.sh--bootstrap-server localhost:9092 --from-beginning --topic topic-testhello world After reading the above, do you have any further understanding of how to perform basic Kafka operations? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Tags: Subject data content copy database basic operation different business message type coefficient control configuration same creation command attribute manual numerical value data table Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information MySQL Xiaomi vpn