Skip to content

bhimrazy/kafka-in-docker-and-python-fastapi

Repository files navigation

Kafka With Python

Setup

kafka.ipynb can be used to get hands on with kafka-python.

    # Compose up
    $ docker-compose up -d

    # Getinto kafka bash
    $ docker exec -it kafka bash

    # Create a topic with name quickstart
    $ kafka-topics --bootstrap-server kafka:9092  --create  --topic quickstart

    # list topics
    $ kafka-topics --list --bootstrap-server kafka:9092

Write messages to the topic

    # Getinto kafka bash
    $ docker exec -it kafka bash

    # produce some message
    $ kafka-console-producer --bootstrap-server kafka:9092  --topic quickstart
    > this is my first kafka message
    > hello world!
    > this is my second kafka message.

    # When you’ve finished, press Ctrl-D to return to your command prompt.

Read messages from the topic

    # Getinto kafka bash
    $ docker exec -it kafka bash

    # consume some message
    $ kafka-console-consumer --bootstrap-server kafka:9092  --topic quickstart --from-beginning

    # When you’ve finished, press Ctrl-C to return to your command prompt.

Stop the Kafka broker

    # Stop containers
    $ docker-compose down

Author

🧾Resources

About

Kafka With Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published