Skip to content

Instantly share code, notes, and snippets.

@nenodias
Last active April 8, 2021 18:07
Show Gist options
  • Save nenodias/aefd0caddb07d11b82c7e7a716924086 to your computer and use it in GitHub Desktop.
Save nenodias/aefd0caddb07d11b82c7e7a716924086 to your computer and use it in GitHub Desktop.
Apache Kafka

Apache Kafka

Entrar no bash do container do kafka para utilizar os binários do mesmo

sudo docker-compose exec kafka /usr/bin/bash

Lista os tópicos

kafka-topics --bootstrap-server localhost:9092 --list

Descrições do tópico

kafka-topics --bootstrap-server localhost:9092 --topic --describe

Cria topico no kafka

kafka-topics --bootstrap-server localhost:9092 --create --topic (--partitions) (--replication-factor)

Excluir tópico

kafka-topics --bootstrap-server localhost:9092 --delte --topic

Alterar topico (Não é permitido haver consumers e producers conectados)

kafka-topics --bootstrap-server localhost:9092 --alter --topic --partitions

Enviar mensagens para um tópico (broker_list recebe uma lista usando virgula como separador)

kafka-console-producer --broker-list localhost:9092 --topic

Consumir mensagens de um tópico

kafka-console-consumer --bootstrap-server localhost:9092 --topic (--from-beginning) (--group )

version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
network_mode: host
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "32181:32181"
kafka:
image: confluentinc/cp-kafka:latest
network_mode: host
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: localhost:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_LOG_RETENTION_HOURS: 24
KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS: 15000
ports:
- "9092:9092"
- "9094:9094"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment