分类
kafka

kafka-console-consumer 对 topic 测试

To listen for messages on a topic:

                                                                                
kafka-console-consumer --bootstrap-server kafka:9092 --topic test1 --from-beginning

To stop the listener session above press: Ctrl+C

To start an interactive message producer session:

kafka-console-producer --broker-list kafka-headless:9092 --topic test1

To create a message in the above session, simply type the message and press “enter”
To end the producer session try: Ctrl+C

If you specify “zookeeper.connect” in configurationOverrides, please replace “kafka-zookeeper:2181” with the value of “zookeeper.connect”, or you will get error.

分类
kafka

kubernetes kafka-client

镜像使用 https://hub.docker.com/r/confluentinc/cp-kafka/

kubectl apply -f kafka-client.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka-client
  namespace: app
spec:
  selector:
    matchLabels:
      app: kafka-client
  template:
    metadata:
      labels:
        app: kafka-client
    spec:
      containers:
        - name: kafka-client
          image: confluentinc/cp-kafka
          imagePullPolicy: IfNotPresent
          command: ["sleep"]
          args: ["infinity"]

长时间跑在 front 或者使用

        command:
          - sh
          - -c
          - "exec tail -f /dev/null"
分类
kafka

kafka 查看 group id 和 offset

查看所有 group id

 bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --list

描述具体的 group id

 bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --describe --group test-consumer-group
分类
kafka

kafka topic 创建和删除

创建

bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic api-gateway --partitions 1 --replication-factor 3

删除

bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic api-gateway

查看

/kafka-topics.sh --list --zookeeper localhost:2181
分类
kafka

kafka修改 topic retention

查看所有的 topic

bin/kafka-topics.sh --list --zookeeper localhost:2181

修改为 60s


# bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-name provider-service --entity-type topics --add-config retention.ms=60000

查看

# bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-name provider-service --entity-type topics
Configs for topics:provider-service are retention.ms=60000