Initialize project and add some simple REST end points
This commit is contained in:
commit
3a3f488841
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@ -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
|
49
README.md
Normal file
49
README.md
Normal file
@ -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`
|
||||||
|
|
98
pom.xml
Normal file
98
pom.xml
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.4.4</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.aselimov</groupId>
|
||||||
|
<artifactId>NS</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>NS</name>
|
||||||
|
<description>Example Notification service </description>
|
||||||
|
<url/>
|
||||||
|
<licenses>
|
||||||
|
<license/>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer/>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection/>
|
||||||
|
<developerConnection/>
|
||||||
|
<tag/>
|
||||||
|
<url/>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.kafka</groupId>
|
||||||
|
<artifactId>spring-kafka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.kafka</groupId>
|
||||||
|
<artifactId>spring-kafka-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
13
src/main/java/com/aselimov/NS/NsApplication.java
Normal file
13
src/main/java/com/aselimov/NS/NsApplication.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<String> createNotification(@RequestBody Notification notification) {
|
||||||
|
return ResponseEntity.ok("Notification received: " + notification.getSubject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/health")
|
||||||
|
public ResponseEntity<String> healthCheck() {
|
||||||
|
return ResponseEntity.ok("Notification service running...");
|
||||||
|
}
|
||||||
|
}
|
34
src/main/java/com/aselimov/NS/model/Notification.java
Normal file
34
src/main/java/com/aselimov/NS/model/Notification.java
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
6
src/main/resources/application.properties
Normal file
6
src/main/resources/application.properties
Normal file
@ -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
|
13
src/test/java/com/aselimov/NS/NsApplicationTests.java
Normal file
13
src/test/java/com/aselimov/NS/NsApplicationTests.java
Normal file
@ -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() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user