Spaces:
Sleeping
Sleeping
Task Service - Quick Start Guide
This guide will help you get the Task Service up and running in under 5 minutes.
Prerequisites Checklist
Before starting, ensure you have:
- Java 17 or higher installed
- MongoDB installed and running
- Eureka Server running on port 8085
- User Service running on port 8081 (for full functionality)
Quick Setup (3 Steps)
Step 1: Start MongoDB
# Start MongoDB service
sudo systemctl start mongod
# Verify MongoDB is running
sudo systemctl status mongod
# Or if using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
Step 2: Navigate to TaskService Directory
cd /path/to/Task-Management-System-using-microservices/TaskService
Step 3: Run the Service
# Build and run
./gradlew clean bootRun
# Or build JAR and run
./gradlew clean build
java -jar build/libs/TaskService-0.0.1-SNAPSHOT.jar
Verify Installation
Test 1: Check Service Health
curl http://localhost:8082/tasks
Expected Output: "Welcome to Task Service"
Test 2: Check Eureka Registration
Open browser: http://localhost:8085
Look for TASK-SERVICE in the registered instances.
Test 3: Check Actuator Health
curl http://localhost:8082/actuator/health
Quick Test with Sample Data
1. Get JWT Token from User Service
First, login via User Service to get a JWT token.
2. Create a Task (Admin Only)
curl -X POST http://localhost:8082/api/tasks \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "My First Task",
"description": "Testing task creation",
"deadline": "2024-12-31T23:59:59",
"tags": ["test", "demo"]
}'
3. Get All Tasks
curl -X GET http://localhost:8082/api/tasks \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
4. Get Tasks by Status
curl -X GET "http://localhost:8082/api/tasks?status=PENDING&sortByDeadline=asc" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Common Issues & Quick Fixes
Issue 1: Port 8082 Already in Use
# Find the process
lsof -i :8082
# Kill it
kill -9 <PID>
# Or change port in application.properties
echo "server.port=8083" >> src/main/resources/application.properties
Issue 2: MongoDB Connection Error
# Check if MongoDB is running
sudo systemctl status mongod
# If not, start it
sudo systemctl start mongod
# Check connection
mongo --eval "db.version()"
Issue 3: Eureka Connection Error
# Check if Eureka is running on 8085
curl http://localhost:8085
# If not, start Eureka Server first
cd ../EurekaServerConfiguration
./gradlew bootRun
Issue 4: User Service Connection Error
# Check if User Service is running on 8081
curl http://localhost:8081
# If not, start User Service
cd ../TaskUserService
./gradlew bootRun
Development Mode
Enable Hot Reload
# Run with DevTools for automatic restart
./gradlew bootRun --continuous
Check Logs
# View application logs
tail -f logs/task-service.log
# Or if running in terminal, logs appear in console
Debug Mode
# Run with debug enabled
./gradlew bootRun --debug-jvm
Then attach your IDE debugger to port 5005.
Docker Quick Start
Build Docker Image
# Build the application first
./gradlew clean build
# Build Docker image
docker build -t task-service:latest .
Run Docker Container
docker run -d \
-p 8082:8082 \
-e SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017/tasks \
-e EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://host.docker.internal:8085/eureka \
--name task-service \
task-service:latest
Check Container Logs
docker logs -f task-service
Using Docker Compose (Recommended)
Start All Services
# From the root directory
docker-compose up task-service
# Or start all services
docker-compose up
Stop Services
docker-compose down
Environment Configuration
Development (Default)
# Uses localhost for all services
server.port=8082
spring.data.mongodb.uri=mongodb://localhost:27017/tasks
eureka.client.service-url.defaultZone=http://localhost:8085/eureka
Docker
# Uses container names for service discovery
spring.data.mongodb.uri=mongodb://mongodb:27017/tasks
eureka.client.service-url.defaultZone=http://eureka-server:8085/eureka
Testing the API
Using cURL
See examples above or check API_REFERENCE.md
Using Postman
- Import the API endpoints from
API_REFERENCE.md - Set up environment variables:
BASE_URL: http://localhost:8082JWT_TOKEN: Your token from User Service
- Set Authorization header:
Bearer {{JWT_TOKEN}}
Using HTTPie
# Install HTTPie
pip install httpie
# Test endpoint
http GET localhost:8082/tasks
# Create task
http POST localhost:8082/api/tasks \
Authorization:"Bearer YOUR_TOKEN" \
title="Test Task" \
description="Testing with HTTPie" \
deadline="2024-12-31T23:59:59"
Next Steps
- β
Read the README: Full documentation in
README.md - β
Check API Reference: Complete API docs in
API_REFERENCE.md - β
Review Changes: See what was improved in
CHANGELOG.md - β Explore Code: All classes have comprehensive JavaDoc
Useful Commands
Gradle Commands
# Clean build
./gradlew clean build
# Run tests
./gradlew test
# Run application
./gradlew bootRun
# Build without tests
./gradlew build -x test
# Show dependencies
./gradlew dependencies
MongoDB Commands
# Connect to MongoDB
mongo
# Use tasks database
use tasks
# Show all tasks
db.Tasks.find().pretty()
# Count tasks
db.Tasks.count()
# Clear all tasks (careful!)
db.Tasks.deleteMany({})
Service Commands
# Check if service is running
curl http://localhost:8082/tasks
# Check Eureka registration
curl http://localhost:8085/eureka/apps/TASK-SERVICE
# Check actuator health
curl http://localhost:8082/actuator/health
# Check actuator metrics
curl http://localhost:8082/actuator/metrics
Getting Help
Documentation
- README.md - Complete service documentation
- API_REFERENCE.md - API endpoint reference
- CHANGELOG.md - Version history
- SUMMARY.md - Code review summary
Logs
Check logs for detailed error information:
# Application logs
tail -f logs/task-service.log
# Docker logs
docker logs -f task-service
# Gradle output
./gradlew bootRun --info
Common Endpoints
- Health: http://localhost:8082/tasks
- Actuator: http://localhost:8082/actuator
- Eureka Dashboard: http://localhost:8085
Ready to Go! π
Your Task Service should now be running on http://localhost:8082
Try the health check:
curl http://localhost:8082/tasks
If you see "Welcome to Task Service", you're all set! π
Happy Coding! π»