Created
February 11, 2026 06:13
-
-
Save rajeshpv/75ad242a768a3ec8bd1f238960dab2ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # requires-python = ">=3.13" | |
| # dependencies = [ | |
| # "kafka-python", | |
| # ] | |
| # /// | |
| """Connect to Kafka and read messages from the fcs topic.""" | |
| import os | |
| from kafka import KafkaConsumer | |
| BOOTSTRAP_SERVERS = os.getenv("KAFKA_BOOTSTRAP_SERVERS", "localhost:9092").split(",") | |
| TOPIC = os.getenv("TOPIC_NAME", "UNKNOWN_TOPIC") | |
| consumer = KafkaConsumer( | |
| TOPIC, | |
| bootstrap_servers=BOOTSTRAP_SERVERS, | |
| group_id="kafka-test-consumer-1", | |
| auto_offset_reset="earliest", | |
| ) | |
| try: | |
| count = 0 | |
| for msg in consumer: | |
| if count >= 10: | |
| break | |
| key = msg.key.decode() if msg.key else None | |
| value = msg.value.decode() if msg.value else None | |
| print(f"partition={msg.partition} offset={msg.offset} key={key} value={value}") | |
| count += 1 | |
| finally: | |
| consumer.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment