> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# scripts/peek_topic.py

> Print the first few messages in our Kafka topic, to check the producer works.

`scripts/peek_topic.py` · chapter [Replaying the data](https://calendar-effects.mintlify.site/tour/04-replaying.md), file 4 · 24 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/scripts/peek_topic.py)

## What it does

Print the first few messages in our Kafka topic, to check the producer works.

Run:   python3 scripts/peek\_topic.py            (add --bootstrap localhost:9092 for local)

## Connections

**Uses:** [`src/common/contracts.py`](https://calendar-effects.mintlify.site/reference/src/common/contracts), [`src/common/settings.py`](https://calendar-effects.mintlify.site/reference/src/common/settings)

## Source

```python title="scripts/peek_topic.py" lines expandable theme={null}
"""Print the first few messages in our Kafka topic, to check the producer works.

Run:   python3 scripts/peek_topic.py            (add --bootstrap localhost:9092 for local)
"""
import argparse

from kafka import KafkaConsumer

from common.contracts import KAFKA_TOPICS
from common.settings import KAFKA_BOOTSTRAP

parser = argparse.ArgumentParser()
parser.add_argument('--bootstrap', default=KAFKA_BOOTSTRAP)
parser.add_argument('--topic', default=KAFKA_TOPICS['master'])
parser.add_argument('-n', type=int, default=5)
args = parser.parse_args()

consumer = KafkaConsumer(args.topic, bootstrap_servers=args.bootstrap.split(','),
                         auto_offset_reset='earliest', consumer_timeout_ms=10000)
for i, msg in enumerate(consumer):
    print(msg.key.decode(), msg.value.decode())
    if i + 1 >= args.n:
        break
consumer.close()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.