Skip to content

#2673: Microservice pattern: Polling publisher #3243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
faf0a12
added new microservice pattern polling-publisher, created folder stru…
quantdevv Feb 27, 2025
c4e9276
added two service polling service & publisher service to handle two d…
quantdevv Mar 12, 2025
0051d3f
polling-publisher service implementation
quantdevv Mar 21, 2025
a2b8743
fixed checkstyle errors
quantdevv Mar 21, 2025
4988d2e
subscriber-service implementation
quantdevv Mar 21, 2025
bb065d3
added entry point for subscriber service & unit test-case
quantdevv Mar 21, 2025
931ab84
added unit test-case for DataSourceService class
quantdevv Mar 21, 2025
78f1ea9
resolved dependency & structured classes
quantdevv Apr 3, 2025
a7497c4
implemented Data repository, DataSource Service & added unittest-case…
quantdevv Apr 3, 2025
a7cc2c3
implemented subscriber microservice using kafkaConsumer
quantdevv Apr 3, 2025
46abbfb
Fixed Kafka bug & added a controller to send message using API
quantdevv Apr 3, 2025
1b3d933
Fixed subscriber-service & updated pom.xml
quantdevv Apr 3, 2025
a59362c
Fixed topic name
quantdevv Apr 3, 2025
5aa46ac
added new listener for other topic
quantdevv Apr 3, 2025
4eeb011
updated all README.md
quantdevv Apr 3, 2025
24b87bb
added description on both application.yaml file
quantdevv Apr 6, 2025
5e3c951
synced with remote branch
quantdevv Apr 6, 2025
84d08f0
added scope before class definition in Test classes & removed duplica…
quantdevv Apr 6, 2025
059f292
added polling-publisher module in pom.xml
quantdevv Apr 6, 2025
8c50536
Merge branch 'master' into issue-2673
quantdevv Apr 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.cleanarchitecture;

import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand All @@ -24,7 +22,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.iluwatar.cleanarchitecture;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using ZK framework
* licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* This project is licensed under the MIT license.
* Module model-view-viewmodel is using
* ZK framework licensed under LGPL (see lgpl-3.0.txt).
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Provides classes and interfaces for the clean architecture pattern implementation.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.cleanarchitecture;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.cleanarchitecture;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
47 changes: 47 additions & 0 deletions polling-publisher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Polling Publisher-Subscriber Microservice Pattern
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


This project implements a **Polling Publisher-Subscriber** system using **Spring Boot** and **Apache Kafka**. It consists of two microservices:

1. **Publisher Service** → Periodically polls a data source and publishes updates via Kafka.
2. **Subscriber Service** → Listens to Kafka for updates and processes them.

## 📌 **Project Structure**
```
polling-publisher-subscriber/
│️— pom.xml (Parent POM)
│️— README.md (This file)
├── polling-service/
│ ├── src/main/java/com/iluwatar/polling/
│ ├── src/main/resources/application.yml
│ ├── pom.xml
│ └── README.md (Polling-specific documentation)
├── subscriber-service/
│ ├── src/main/java/com/iluwatar/subscriber/
│ ├── src/main/resources/application.yml
│ ├── pom.xml
│ └── README.md (Subscriber-specific documentation)
```

## 🚀 **Tech Stack**
- **Spring Boot** (Microservices)
- **Apache Kafka** (Messaging)
- **Maven** (Build Tool)

## 🛠 **Setup & Running**
### 1️⃣ **Start Kafka & Zookeeper**
If you don’t have Kafka installed, use Docker:
```sh
docker-compose up -d
```

### 2️⃣ **Build the Project**
```sh
mvn clean install
```

### 3️⃣ **Run Service**
```sh
mvn spring-boot:run
```
2 changes: 2 additions & 0 deletions polling-publisher/etc/polling-publisher.urm.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@startuml
@enduml
41 changes: 41 additions & 0 deletions polling-publisher/polling-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# **Publisher(Polling)**
**README.md** (Inside `polling-module/`)


## Publisher Microservice

This module is responsible for **polling a data source** at regular intervals and publishing updates to Kafka.

## **How It Works**
- Uses a **scheduler** to poll data periodically.
- Sends updates to Kafka
- Exposes an API to manually trigger polling.

## **Project Structure**

```
publisher-module/
│️— src/main/java/com/iluawatar/polling/
| ├── App.java
│ ├── DataRepository.java
│ ├── DataSourceService.java
│ ├── KafkaProducer.java
│ ├── PollingController.java
│ └── PollingScheduler.java
│️— pom.xml
│️— README.md (This file)

```

## 🛠 **Running the Publisher**
```sh
mvn spring-boot:run
```

## 📝 **Endpoints**
| Method | Endpoint | Description |
|--------|------------------|----------------------------------|
| `GET` | `/health` | check health of polling |
| `POST` | `/send?message=""` | Manually trigger data publishing |

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@startuml
@enduml
59 changes: 59 additions & 0 deletions polling-publisher/polling-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).

The MIT License
Copyright © 2014-2022 Ilkka Seppälä

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-->
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>polling-publisher</artifactId>
<version>1.26.0-SNAPSHOT</version>
</parent>

<artifactId>polling-service</artifactId>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<configuration>
<archive>
<manifest>
<mainClass>com.iluwatar.polling-service.App</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading
Loading