zoukankan      html  css  js  c++  java
  • kafka2.5.0基本命令

    本博文所使用kafka版本2.5.0,操作系统centos8.

    1)启动zookeeper

    演示用的话,直接启动kafka自带的zookeeper即可:

    cd kafkaDirectory/kafka_2.12-2.5.0
    bin/zookeeper-server-start.sh config/zookeeper.properties

    生产上建议连接到zookeeper集群,需更改配置文件 config/server.properties 里更改zookeeper配置zookeeper.connect=localhost:2181

    2) 启动kafka server

    cd kafkaDirectory/kafka_2.12-2.5.0
    bin/kafka-server-start.sh config/server.properties

     3) 主题topic 

     创建 test Topic,一个partitions分区,一个replication-factor副本:

    bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

    列出topic:

    bin/kafka-topics.sh --list --bootstrap-server localhost:9092

    往test Topic里发送数据:

    bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test

    从test Topic里面从头开始消费数据:

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

    更多kafka Topic相关细节请移步至: 《kafka2.5.0 主题Topic

    4) 本机搭建kafka集群

    复制多个server.properties文件:

    cp config/server.properties config/server-1.properties
    cp config/server.properties config/server-2.properties

    修改server-1.properties:

        broker.id=1
        listeners=PLAINTEXT://:9093
        log.dirs=/tmp/kafka-logs-9093

    修改server-2.properties:

        broker.id=2
        listeners=PLAINTEXT://:9094
        log.dirs=/tmp/kafka-logs-9094

    注意: broker.id 是每个节点唯一的id,并且永恒不变的。

     5)查看Topic详情

    查看Topic详情命令:

    bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test  // 命令输出:
    Topic:test  PartitionCount:1    ReplicationFactor:1 Configs:
        Topic: test Partition: 0    Leader: 0   Replicas: 0 Isr: 0
     6)生产者发送消息
    bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic my-replicated-topic
    my test message 1
    my test message 2

    7)消费者消费消息

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
    my test message 1
    my test message 2
     

    end.

     

  • 相关阅读:
    Handling Errors and Exceptions
    Advanced Features of Delphi DLLs
    How to put a relative path for a DLL statically loaded?
    Delphi DLL制作和加载 Static, Dynamic, Delayed 以及 Shared-Memory Manager
    The useful App Paths registry key : HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Paths
    DLL Dynamic-Link Library Search Order
    Can a windows dll retrieve its own filename?
    Restrict form resize -- Delphi
    Programmer in Google Code
    How to open a web site with the default web browser in a NEW window
  • 原文地址:https://www.cnblogs.com/zhuwenjoyce/p/13172473.html
Copyright © 2011-2022 走看看