Skip to content

Notification service built with Java and Spring Boot. Handles EMAIL, SMS, and PUSH events using separate queues with async processing and status callbacks.

Notifications You must be signed in to change notification settings

gajendra-ingle/Event-Notification-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”” Event Notification System

Build Status Dockerized License: MIT Lines of Code Visitor Badge Last Commit

A Java-based REST API system that accepts and processes EMAIL, SMS, and PUSH notification events asynchronously. Events are handled in separate FIFO queues and callbacks are sent to clients on completion.

🎯 Objective

To build a simple, scalable notification system with asynchronous processing using Java and Spring Boot, complete with Docker support, callback integration, graceful shutdown, and unit testing.

βœ… Features

  • Accepts notification events via REST API (/api/events)
  • Processes EMAIL, SMS, and PUSH events in separate FIFO queues
  • Simulated processing delays (EMAIL: 5s, SMS: 3s, PUSH: 2s)
  • Simulates random failure (10% of events)
  • Sends HTTP POST callback on success/failure
  • Graceful shutdown (finishes in-progress tasks before exit)
  • Fully Dockerized
  • JUnit-based unit testing

πŸ›  Tech Stack

Technology Purpose
Java 17 Programming language
Spring Boot 3 REST API and background task management
Maven Project and dependency management
WebClient Async HTTP client for callbacks
Docker Containerization
Docker Compose Local multi-service environment
JUnit 5 Unit testing

πŸ” Supported Events

1. EMAIL Event

  • πŸ“§ Sends email
  • ⏱ 5 seconds simulated processing time

Payload Example

{
  "eventType": "EMAIL",
  "payload": {
    "recipient": "user@example.com",
    "message": "Welcome to our service!"
  },
  "callbackUrl": "http://client.com/callback"
}

2. SMS Event

  • πŸ“± Sends SMS
  • ⏱ 3 seconds simulated processing time

Payload Example

{
  "eventType": "SMS",
  "payload": {
    "phoneNumber": "+919876543210",
    "message": "Your OTP is 123456"
  },
  "callbackUrl": "http://client.com/callback"
}

3. PUSH Event

  • πŸ”” Sends push notification to device
  • ⏱ 2 seconds simulated processing time

Payload Example

{
  "eventType": "PUSH",
  "payload": {
    "deviceId": "xyz-abc-123",
    "message": "Your order is out for delivery"
  },
  "callbackUrl": "http://client.com/callback"
}

πŸ“‘ Callback Status

Once processing completes, your system will receive an HTTP POST request to the callback URL.

βœ… Success Callback

{
  "eventId": "e123",
  "status": "COMPLETED",
  "eventType": "EMAIL",
  "processedAt": "2025-07-01T12:34:56Z"
}

❌ Failure Callback

{
  "eventId": "e123",
  "status": "FAILED",
  "eventType": "SMS",
  "errorMessage": "Simulated processing failure",
  "processedAt": "2025-07-01T12:34:56Z"
}

πŸ“¦ API Endpoint

POST /api/events

Submits a new notification event for asynchronous processing and delivery.

πŸ“€ Request Format

{
  "eventType": "EMAIL",
  "payload": {
    "recipient": "user@example.com",
    "message": "Welcome to the service!"
  },
  "callbackUrl": "http://client.com/callback"
}

πŸ“ Note

  • eventType: "EMAIL", "SMS", "PUSH"
  • payload: Varies based on eventType
  • callbackUrl: For receiving async delivery status updates

πŸ“₯ Response Format

{
  "eventId": "e123",
  "message": "Event accepted for processing."
}

πŸš€ How to Run

πŸ–₯ Run Locally

./mvnw clean install -DskipTests
java -jar target/event-notification-system-1.0.0.jar

Visit: http://localhost:8080/api/events

🐳 Run with Docker

docker compose up --build

πŸ§ͺ Run Tests

./mvnw test

Test coverage includes:

  • Event creation & routing
  • FIFO queueing per event type
  • Callback delivery
  • Graceful shutdown
  • Simulated failures

πŸ“ Project Structure

Event-Notification-System/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/com/sprih/eventnotificationsystem/
β”‚   β”‚   β”‚   β”œβ”€β”€ controller/               # REST endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/                      # Request/response data transfer objects
β”‚   β”‚   β”‚   β”œβ”€β”€ enums/                    # Enum definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ service/                  # Service interfaces and implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ util/                     # Utility classes
β”‚   β”‚   β”‚   β”œβ”€β”€ config/                   # Configuration 
β”‚   β”‚   β”‚   └── EventNotificationApplication.java  # Main Spring Boot application
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.yml          # Spring Boot app configuration
β”‚   β”‚
β”‚   └── test/java/com/sprih/eventnotificationsystem/
β”‚       β”œβ”€β”€ controller/                  # Unit tests for controllers
β”‚       β”œβ”€β”€ service/                     # Unit tests for services
β”‚       └── ...                          # Other tests 
β”‚
β”œβ”€β”€ Dockerfile                           # Docker build definition
β”œβ”€β”€ docker-compose.yml                   # Docker multi-container setup
β”œβ”€β”€ pom.xml                              # Maven build and dependencies config
└── README.md                            # Project documentation

πŸ”‘ Advantages

  • FIFO processing per event type
  • Clear separation of concerns
  • Fault-tolerant with retry-ready design
  • Lightweight, Docker-ready deployment
  • Easily testable with JUnit

πŸ§ͺ Sample Test Scenarios

Test Case Expected Outcome
Valid EMAIL event Added to EMAIL queue, processed in FIFO
Invalid event type Returns 400 Bad Request
Missing fields Returns 400 Bad Request
Simulated failure 10% events return FAILED
Callback triggered POST sent to callback URL
Graceful shutdown New requests rejected, queues drained
Thread cleanup All threads shutdown cleanly

🀝 Contributing

We welcome contributions! To get started:

  1. Fork the repository
  2. Create a new branch:
git checkout -b feature/your-feature-name
  1. Make your changes
  2. Commit your code:
git commit -m "Add new feature"
  1. Push to your branch:
git push origin feature/your-feature-name
  1. Submit a pull request βœ…

πŸ“œ License

This project is licensed under the MIT License.

πŸ™‹β€β™‚οΈ Author

Gajendra Ingle
Software Engineer | Pune, India
πŸ“§ Email: gajendraingle01@gmail.com
πŸ”— GitHub: github.com/gajendra-ingle
πŸ’Ό LinkedIn: linkedin.com/in/gajendraingle

About

Notification service built with Java and Spring Boot. Handles EMAIL, SMS, and PUSH events using separate queues with async processing and status callbacks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published