commit 3a3f488841447449b6a1ecd0e5c9ac379e05edad Author: Alex Selimov Date: Sat Apr 12 20:08:24 2025 -0400 Initialize project and add some simple REST end points diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1198c2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html +.DS_Store +.attach_pid* +.classpath +.factorypath +.gradle +.metadata +.project +.recommenders +.settings +.springBeans +.vscode +/code +MANIFEST.MF +_site/ +activemq-data +bin +build +!/**/src/**/bin +!/**/src/**/build +build.log +dependency-reduced-pom.xml +dump.rdb +interpolated*.xml +lib/ +manifest.yml +out +overridedb.* +target +.flattened-pom.xml +secrets.yml +.gradletasknamecache +.sts4-cache +.git-hooks/ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..5bc22c4 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Notification System + +A scalable backend system for managing and delivering various types of notifications using modern technologies. + +## Overview + +This project demonstrates a notification processing pipeline built with Java Spring Boot, Apache Kafka, and MongoDB. It processes notification requests from multiple sources and delivers them through different channels (email, SMS, push notifications). + +## Tech Stack + +- **Java 17+**: Core programming language +- **Spring Boot 3.2.x**: Application framework +- **Apache Kafka**: Message queue for notification processing +- **MongoDB**: Database for storing notification records +- **Maven**: Build and dependency management + +## Features + +- REST API for notification submission +- Asynchronous processing with Kafka +- Multiple notification types (Email, SMS, Push) +- Status tracking and delivery confirmation +- Retry mechanisms for failed notifications +- Metrics and monitoring endpoints + +## Getting Started + +### Prerequisites + +- Java JDK 17 or 21 +- Maven (or use the Maven wrapper) +- MongoDB (local installation or Docker) +- Kafka (local installation or Docker) + +### Running the Application + +1. Clone the repository + ``` + git clone https://www.alexselimov.com/git/aselimov/NotificationServer.git + cd NotificationServer + ``` + +2. Build and run the application + ``` + mvn spring-boot:run + ``` + +3. The service will be available at `http://localhost:8080` + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cbbce49 --- /dev/null +++ b/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.aselimov + NS + 0.0.1-SNAPSHOT + NS + Example Notification service + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.kafka + spring-kafka + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.kafka + spring-kafka-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/com/aselimov/NS/NsApplication.java b/src/main/java/com/aselimov/NS/NsApplication.java new file mode 100644 index 0000000..6b55156 --- /dev/null +++ b/src/main/java/com/aselimov/NS/NsApplication.java @@ -0,0 +1,13 @@ +package com.aselimov.NS; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class NsApplication { + + public static void main(String[] args) { + SpringApplication.run(NsApplication.class, args); + } + +} diff --git a/src/main/java/com/aselimov/NS/controller/NotificationController.java b/src/main/java/com/aselimov/NS/controller/NotificationController.java new file mode 100644 index 0000000..8d6fb96 --- /dev/null +++ b/src/main/java/com/aselimov/NS/controller/NotificationController.java @@ -0,0 +1,20 @@ +package com.aselimov.NS.controller; + +import com.aselimov.NS.model.Notification; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/notifications") +public class NotificationController { + + @PostMapping + public ResponseEntity createNotification(@RequestBody Notification notification) { + return ResponseEntity.ok("Notification received: " + notification.getSubject()); + } + + @GetMapping("/health") + public ResponseEntity healthCheck() { + return ResponseEntity.ok("Notification service running..."); + } +} diff --git a/src/main/java/com/aselimov/NS/model/Notification.java b/src/main/java/com/aselimov/NS/model/Notification.java new file mode 100644 index 0000000..0d1a88a --- /dev/null +++ b/src/main/java/com/aselimov/NS/model/Notification.java @@ -0,0 +1,34 @@ +package com.aselimov.NS.model; + +import java.time.LocalDateTime; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Document(collection = "notifications") +public class Notification { + @Id + private String id; + private NotificationType type; + private String recipient; + private String subject; + private String content; + private NotificationStatus status; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public enum NotificationType { + EMAIL, SMS, PUSH + } + + public enum NotificationStatus { + PENDING, SENT, FAILED + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..87e4853 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=NS + +server.port=8080 +spring.data.mongodb.uri=mongodb://localhost:27017/notification-system +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.consumer.group-id=notification-group diff --git a/src/test/java/com/aselimov/NS/NsApplicationTests.java b/src/test/java/com/aselimov/NS/NsApplicationTests.java new file mode 100644 index 0000000..d17d5d4 --- /dev/null +++ b/src/test/java/com/aselimov/NS/NsApplicationTests.java @@ -0,0 +1,13 @@ +package com.aselimov.NS; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class NsApplicationTests { + + @Test + void contextLoads() { + } + +}