Open jms0522 opened 2 months ago
kafka-topics.sh --list --bootstrap-server localhost:9092
kafka-topics.sh --create \ --topic <ν ν½μ΄λ¦> \ --partitions <νν°μ μ> \ --replication-factor <볡μ λ³Έμ> \ --bootstrap-server localhost:9092
kafka-topics.sh --describe \ --topic <ν ν½μ΄λ¦> \ --bootstrap-server localhost:9092
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic new_test_topic --from-beginning
pip install kafka-python from kafka.admin import KafkaAdminClient, NewTopic from kafka import KafkaConsumer # Kafka ν΄λΌμ΄μΈνΈ μ€μ admin_client = KafkaAdminClient( bootstrap_servers="localhost:9092", client_id='kafka-python-example' ) # ν ν½ μμ± ν¨μ def create_topic(topic_name, num_partitions=3, replication_factor=1): topic = NewTopic(name=topic_name, num_partitions=num_partitions, replication_factor=replication_factor) admin_client.create_topics(new_topics=[topic], validate_only=False) print(f"Topic '{topic_name}' created successfully.") # ν ν½ λͺ©λ‘ νμΈ ν¨μ def list_topics(): consumer = KafkaConsumer(bootstrap_servers="localhost:9092") topics = consumer.topics() print("Topics:", topics) # ν ν½ μμ± create_topic("logstash-topic") # ν ν½ λͺ©λ‘ νμΈ list_topics()
environment: KAFKA_CREATE_TOPICS: "logstash-topic:3:1" # ν ν½ μμ±: logstash-topic, νν°μ 3, 볡μ λ³Έ 1
μ΄λ°μμΌλ‘ μμμ μμ±ν μ μμ.
command: > sh -c " /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties & sleep 5; /opt/kafka/bin/kafka-topics.sh --create --topic logstash-topic --partitions 3 --replication-factor 1 --if-not-exists --bootstrap-server localhost:9092; /opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092; wait "
μ΄λ°μμΌλ‘ μ ν΄λλ©΄ μ€ν¬λ¦½νΈλ‘ μ€νλλ€. λ¨ shνμΌμ 미리 μ‘΄μ¬ν΄μΌν¨.
/opt/kafka_2.13-2.8.1/config/server.properties
logstash conf μμ kafka topicμ μ€μ
컨ν μ΄λ λ΄λΆ kafka-topic.sh μλ κ³³μμ μ€ννκ±°λ docker exec -itλ₯Ό μ¬μ©ν΄μ μΈλΆμμ μ€ν
ν ν½ λͺ©λ‘ νμΈ
ν ν½ μμ±
μ 보 νμΈ
λ°μ΄ν° λ€μ΄μ€λμ§ νμΈ
Python μ½λλ‘ ν ν½ μμ± λ° λͺ©λ‘ νμΈ (kakfa-python)
μ€μΉ
docker-composeλ₯Ό ν΅ν΄ μμμ ν ν½ μμ±λ κ°λ₯νλ€.
μ΄λ°μμΌλ‘ μμμ μμ±ν μ μμ.
μ€ν¬λ¦½νΈλ₯Ό ν΅ν΄μ μμ±λ κ°λ₯νλ€.
μ΄λ°μμΌλ‘ μ ν΄λλ©΄ μ€ν¬λ¦½νΈλ‘ μ€νλλ€. λ¨ shνμΌμ 미리 μ‘΄μ¬ν΄μΌν¨.