3. Logistics Service Mongodb Edition‐ Step‐by‐Step Guide - Wiz-DevTech/prettygirllz GitHub Wiki
# Verify Java & Maven
java -version # Requires 17+
mvn -v # Requires 3.9+
# Install Docker
sudo apt-get update && sudo apt-get install docker.io docker-compose # Linux
brew install docker docker-compose # Mac
git clone https://github.com/your-org/logistics-service.git
cd logistics-service
docker-compose up -d mongodb kafka redis
# Check MongoDB
docker exec -it mongodb mongosh --eval "db.runCommand({ping:1})"
# Check Kafka
docker exec -it kafka kafka-topics --list --bootstrap-server localhost:9092
# Check Redis
docker exec -it redis redis-cli PING
cat <<EOF > .env
SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/logistics
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
FRAUD_THRESHOLD=0.85
EOF
docker exec -it mongodb mongosh --eval "
use logistics;
db.createCollection('deliveries');
db.createCollection('fraud_blacklist');
"
mvn clean install -DskipTests
mvn spring-boot:run -Dspring-boot.run.profiles=dev
Verify Startup:
2024-02-20T10:00:00 INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port 8080
mvn test
Key Test Classes:
DeliveryOrchestratorServiceUnitTest
FraudDetectionServiceTest
mvn verify -Pintegration-test
Test Coverage:
- MongoDB repository operations
- Kafka event publishing/consumption
- Redis cache interactions
Create Test Delivery:
curl -X POST http://localhost:8080/api/v1/deliveries \
-H "Content-Type: application/json" \
-d '{
"orderId": "test_ord_1",
"destinationType": "HOME",
"recipient": {
"phone": "+15551234567"
}
}'
Force Error Scenario:
curl -X POST http://localhost:8080/api/v1/deliveries \
-H "X-TEST-MODE: FAIL_HDS" \
-d '{"orderId": "fail_ord_1", "destinationType": "HOME"}'
docker exec -it mongodb mongosh logistics --eval "
db.deliveries.find().pretty();
db.fraud_blacklist.find().pretty();
"
docker exec -it kafka kafka-console-consumer \
--bootstrap-server localhost:9092 \
--topic delivery-events \
--from-beginning
docker exec -it redis redis-cli KEYS "*delivery*"
Common Issues Table:
Symptom | Diagnostic Command | Solution |
---|---|---|
MongoDB connection refused | docker logs mongodb |
Check .env URI |
Kafka consumer lag | docker exec kafka kafka-consumer-groups --describe |
Increase partitions |
High API latency | curl -o /dev/null -s -w '%{time_total}' http://localhost:8080/actuator/health |
Check Redis connection pool |
# Stop containers
docker-compose down
# Remove test data
docker exec -it mongodb mongosh logistics --eval "db.dropDatabase()"
- Set up CI/CD pipeline
- Configure Prometheus monitoring
- Implement chaos engineering tests
Pro Tip: Use the included test-data-generator.sh
for load testing:
./scripts/test-data-generator.sh --orders 100 --threads 5
This guide ensures your Logistics Service is properly implemented and ready for integration with other microservices. For advanced scenarios, refer to the Integration Handbook.