This service is responsible for collecting news articles from various sources and storing them in a MongoDB database. It consists of two main components:
- News Polling Service: Polls news from external APIs and writes to Kafka
- News Storage Service: Reads news from Kafka and stores in MongoDB
- Kafka for message queue
- MongoDB for article storage
- Redis for deduplication
- Python with Poetry for dependency management
- Install Docker and Docker Compose
- Copy
env.exampleto.envand fill in required values - Run
docker-compose up -dto start all services
- Polls news from configured sources
- Processes and validates articles
- Writes to Kafka topics
- Consumes articles from Kafka
- Stores in MongoDB with proper indexing
- Handles deduplication and updates
This project supports a full mock data flow for local development and testing. The process is as follows:
- Mock Data Generation: News Polling Service generates unique mock articles for each country/category.
- Kafka Message Flow: Polling Service publishes articles to the
raw-newsKafka topic. - Storage Service Consumption: News Storage Service consumes messages from
raw-newsand writes articles to MongoDB (news_db.articles). - MongoDB Storage: Articles are indexed and deduplicated in MongoDB.
- Start All Services
docker compose up -d --build
- Check Polling Service Logs
You should see logs like
docker compose logs --tail=30 news-polling-service
Sent 3 unique articles to Kafka: .... - Check Storage Service Logs
You should see logs like
docker compose logs --tail=30 news-storage-service
Stored news batch: .... - Check MongoDB for Articles
You should see mock articles with fields like
docker compose exec mongodb mongosh news_db --eval "db.articles.find().limit(3).pretty()"
title,content,category, etc.
- Kafka Consumer Not Receiving Messages: Ensure storage service subscribes to the correct topic (
raw-news). - No Data in MongoDB: Reset the Kafka consumer group offset to earliest:
- Stop storage service:
docker compose stop news-storage-service
- Reset offset:
docker compose exec kafka kafka-consumer-groups --bootstrap-server kafka:29092 --group news_storage_group --topic raw-news --reset-offsets --to-earliest --execute - Restart storage service:
docker compose up -d news-storage-service
- Stop storage service:
- ImportError/Config Errors: Make sure all imports use the correct relative path, e.g.
from ..config.settings import Config. - Kafka Console Consumer (for debugging):
docker compose exec kafka kafka-console-consumer --bootstrap-server kafka:29092 --topic raw-news --from-beginning --max-messages 1
For more details, see the code comments and troubleshooting steps above. If you encounter issues, check the logs for both polling and storage services first.