diff --git a/polling-publisher/README.md b/polling-publisher/README.md
new file mode 100644
index 000000000000..45e02ac59d21
--- /dev/null
+++ b/polling-publisher/README.md
@@ -0,0 +1,119 @@
+---
+title: "Polling Publisher-Subscriber Pattern in Java: Mastering Asynchronous Messaging Elegantly"
+shortTitle: Polling Pub/Sub
+description: "Learn how to implement a Polling Publisher-Subscriber system in Java using Spring Boot and Kafka. Explore the architecture, real-world analogies, and benefits of asynchronous communication with clean code examples."
+category: Architectural
+language: en
+tag:
+ - Spring Boot
+ - Kafka
+ - Microservices
+ - Asynchronous Messaging
+ - Decoupling
+---
+
+## Also known as
+
+* Event-Driven Architecture
+* Asynchronous Pub/Sub Pattern
+* Message Queue-Based Polling System
+
+## Intent of Polling Publisher-Subscriber Pattern
+
+The Polling Publisher-Subscriber pattern decouples data producers from consumers by enabling asynchronous, message-driven communication. A service polls a data source and publishes messages to a message broker (e.g., Kafka), which are then consumed by one or more subscriber services.
+
+## Detailed Explanation of the Pattern with Real-World Examples
+
+### Real-world analogy
+
+> A news agency constantly polls for the latest news updates. Once it receives new information, it publishes them to different news outlets (TV, newspapers, apps). Each outlet consumes and displays the updates independently.
+
+### In plain words
+
+> One service regularly checks for updates (polls) and sends messages to Kafka. Another service listens to Kafka and processes the messages asynchronously.
+
+### Wikipedia says
+
+> This pattern closely resembles the [Publish–subscribe model](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern), where messages are sent by publishers and received by subscribers without them knowing each other.
+
+### Architecture Flow
+
+```
++------------+ +--------+ +-------------+
+| Publisher | ---> | Kafka | ---> | Subscriber |
++------------+ +--------+ +-------------+
+```
+
+## Programmatic Example (Spring Boot + Kafka)
+
+### Publisher Service
+
+- Uses Spring's `@Scheduled` to poll data periodically.
+- Publishes data to a Kafka topic.
+- Optionally exposes a REST API for manual data publishing.
+
+```java
+@Scheduled(fixedRate = 5000)
+public void pollAndPublish() {
+ String data = pollingService.getLatestData();
+ kafkaTemplate.send("updates-topic", data);
+}
+```
+
+### Subscriber Service
+
+- Listens to Kafka topic using `@KafkaListener`.
+- Processes messages asynchronously.
+
+```java
+@KafkaListener(topics = "updates-topic")
+public void processUpdate(String message) {
+ log.info("Received update: {}", message);
+ updateProcessor.handle(message);
+}
+```
+
+## When to Use the Polling Publisher-Subscriber Pattern
+
+Use this pattern when:
+
+* Real-time push from the producer is not possible.
+* Loose coupling between producers and consumers is desired.
+* You need asynchronous, scalable event processing.
+* You are building an event-driven microservices architecture.
+
+## Real-World Applications
+
+* Real-time reporting dashboards
+* Health check aggregators for distributed systems
+* IoT telemetry processing
+* Notification and alerting systems
+
+## Benefits and Trade-offs of Polling Pub/Sub Pattern
+
+### Benefits
+
+* Loose coupling between services
+* Asynchronous and scalable architecture
+* Fault-tolerant with message persistence in Kafka
+* Easy to extend with new consumers or publishers
+
+### Trade-Offs
+
+* Polling introduces latency between data generation and consumption
+* Requires managing and configuring Kafka (or other brokers)
+* Slightly more complex deployment and infrastructure setup
+
+## Related Java Design Patterns
+
+* [Observer Pattern](https://java-design-patterns.com/patterns/observer/)
+* [Mediator Pattern](https://java-design-patterns.com/patterns/mediator/)
+* [Message Queue Pattern](https://java-design-patterns.com/patterns/event-queue/)
+
+## References and Credits
+
+* [Apache Kafka Documentation](https://kafka.apache.org/documentation/)
+* [Spring Kafka Documentation](https://docs.spring.io/spring-kafka)
+* [Spring Scheduled Tasks](https://www.baeldung.com/spring-scheduled-tasks)
+* [Spring Kafka Tutorial – Baeldung](https://www.baeldung.com/spring-kafka)
+* Inspired by: [iluwatar/java-design-patterns](https://github.com/iluwatar/java-design-patterns)
\ No newline at end of file
diff --git a/polling-publisher/etc/polling-publisher.urm.puml b/polling-publisher/etc/polling-publisher.urm.puml
new file mode 100644
index 000000000000..02af47ddf261
--- /dev/null
+++ b/polling-publisher/etc/polling-publisher.urm.puml
@@ -0,0 +1,2 @@
+@startuml
+@enduml
\ No newline at end of file
diff --git a/polling-publisher/polling-service/etc/polling-service.urm.puml b/polling-publisher/polling-service/etc/polling-service.urm.puml
new file mode 100644
index 000000000000..02af47ddf261
--- /dev/null
+++ b/polling-publisher/polling-service/etc/polling-service.urm.puml
@@ -0,0 +1,2 @@
+@startuml
+@enduml
\ No newline at end of file
diff --git a/polling-publisher/polling-service/pom.xml b/polling-publisher/polling-service/pom.xml
new file mode 100644
index 000000000000..a587a96521fe
--- /dev/null
+++ b/polling-publisher/polling-service/pom.xml
@@ -0,0 +1,59 @@
+
+
+
+ 4.0.0
+
+ com.iluwatar
+ polling-publisher
+ 1.26.0-SNAPSHOT
+
+
+ polling-service
+ jar
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.polling-service.App
+
+
+
+
+
+
+
+
+
+
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java
new file mode 100644
index 000000000000..0b5f9f4d00fa
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java
@@ -0,0 +1,45 @@
+/*
+ * 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.polling;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/** Polling-Publisher pattern paradigm. */
+@SpringBootApplication
+@EnableScheduling
+public class App {
+
+ /**
+ * Program entry point.
+ *
+ * @param args command line args.
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(App.class, args);
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java
new file mode 100644
index 000000000000..61483e9dedcf
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java
@@ -0,0 +1,67 @@
+/*
+ * 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.polling;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import org.springframework.stereotype.Repository;
+
+/** Data repository to keep or store data. */
+@Repository
+public class DataRepository {
+
+ private final Map dataStorage = new HashMap<>();
+
+ /** init after map creation ... to put dummy data. */
+ @PostConstruct
+ public void init() {
+ // Injecting dummy data at startup
+ dataStorage.put(2, "Initial Dummy Data - two - 2");
+ dataStorage.put(3, "Initial Dummy Data - three - 3");
+ dataStorage.put(4, "Initial Dummy Data - four - 4");
+ }
+
+ /** Save data to the repository. */
+ public void save(int id, String value) {
+ dataStorage.put(id, value);
+ }
+
+ /** Retrieve data by ID. */
+ public String findById(int id) {
+ return dataStorage.getOrDefault(id, "Data not found");
+ }
+
+ /** Delete data by ID. */
+ public void delete(int id) {
+ dataStorage.remove(id);
+ }
+
+ /** Get all data. */
+ public Map findAll() {
+ return dataStorage;
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java
new file mode 100644
index 000000000000..45dd317fce74
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java
@@ -0,0 +1,81 @@
+/*
+ * 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.polling;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/** This class is responsible for keeping the events. */
+@Service
+public class DataSourceService {
+
+ private static final Logger log = LoggerFactory.getLogger(DataSourceService.class);
+
+ private final DataRepository repository;
+ private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+
+ /** Constructor & Scheduler to push random data. */
+ public DataSourceService(DataRepository repository) {
+ this.repository = repository;
+ scheduleDataGeneration();
+ }
+
+ private void scheduleDataGeneration() {
+ Random random = new Random();
+ scheduler.scheduleAtFixedRate(
+ () -> {
+ int id = random.nextInt(100); // Random ID
+ String value = "Auto-Data-" + id;
+ this.addData(id, value);
+ log.info("🔵 Data Added: {} -> {}", id, value);
+ },
+ 0,
+ 3,
+ TimeUnit.SECONDS);
+ }
+
+ public void addData(int id, String value) {
+ repository.save(id, value);
+ }
+
+ public String getData(int id) {
+ return repository.findById(id);
+ }
+
+ public void removeData(int id) {
+ repository.delete(id);
+ }
+
+ public Map getAllData() {
+ return repository.findAll();
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java
new file mode 100644
index 000000000000..23479f83250a
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.polling;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.stereotype.Component;
+
+/** This class is responsible for sending messages to Kafka. */
+@Component
+public class KafkaProducer {
+
+ @Autowired private final KafkaTemplate kafkaTemplate;
+
+ public KafkaProducer(KafkaTemplate kafkaTemplate) {
+ this.kafkaTemplate = kafkaTemplate;
+ }
+
+ /**
+ * Sends a message to the Kafka topic.
+ *
+ * @param message The message to send.
+ */
+ public void sendMessage(String topic, String message) {
+ kafkaTemplate.send(topic, message);
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java
new file mode 100644
index 000000000000..cf78fc716c19
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java
@@ -0,0 +1,50 @@
+/*
+ * 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.polling;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/** This class is responsible for contolling polling tasks. */
+@RestController
+public class PollingController {
+
+ @Autowired private KafkaProducer kafkaProducer;
+
+ @GetMapping("/health")
+ public String healthCheck() {
+ return "Polling Service is up and running!";
+ }
+
+ @PostMapping("/send")
+ public String sendMessage(@RequestParam("message") String message) {
+ kafkaProducer.sendMessage("API", message);
+ return "Message sent: " + message;
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java
new file mode 100644
index 000000000000..5c8361c2ff67
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java
@@ -0,0 +1,61 @@
+/*
+ * 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.polling;
+
+import java.util.Random;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/** This class is responsible for scheduling polling tasks. */
+@Component
+public class PollingScheduler {
+
+ private static final Logger log = LoggerFactory.getLogger(PollingScheduler.class);
+ @Autowired private DataSourceService dataSourceService;
+ @Autowired private KafkaProducer kafkaProducer;
+
+ /** Scheduler for poll data on each 5 second. */
+ @Scheduled(fixedRate = 5000) // Poll every 5 seconds
+ public void pollDataSource() {
+ try {
+ int id = new Random().nextInt(100); // Pick a random ID
+ String data = dataSourceService.getData(id); // Get data from service
+
+ if (data != null) {
+ log.info("🟢 Publishing Data: {}", data);
+ kafkaProducer.sendMessage("updates", data);
+ } else {
+ log.info("🔴 No Data Found for ID: {}", id);
+ }
+ } catch (Exception e) {
+ log.error("Error while publishing data {}", e.getMessage());
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/polling-publisher/polling-service/src/main/resources/application.yml b/polling-publisher/polling-service/src/main/resources/application.yml
new file mode 100644
index 000000000000..3ad766e6d017
--- /dev/null
+++ b/polling-publisher/polling-service/src/main/resources/application.yml
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+server:
+ port: 8081
+
+spring:
+ kafka:
+ bootstrap-servers: localhost:9092 # Kafka broker address(es)
+ consumer:
+ group-id: subscriber-group # Consumer group ID
+ auto-offset-reset: earliest # How to reset offset on consumer startup
+ # Add other consumer properties here
+
diff --git a/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java
new file mode 100644
index 000000000000..d54972662be7
--- /dev/null
+++ b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.polling;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class AppTest {
+
+ @Test
+ void polling() {
+ assertDoesNotThrow(() -> App.main(new String[] {}));
+ }
+}
diff --git a/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java
new file mode 100644
index 000000000000..034019462a02
--- /dev/null
+++ b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.polling;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class DataRepositoryTest {
+
+ private DataRepository repository;
+
+ @BeforeEach
+ void setUp() {
+ repository = new DataRepository(); // Initialize before each test
+ }
+
+ @Test
+ void testSaveAndFindById() {
+ repository.save(1, "Test Data");
+
+ String result = repository.findById(1);
+
+ assertEquals("Test Data", result, "The retrieved data should match the stored value.");
+ }
+
+ @Test
+ void testFindById_NotFound() {
+ String result = repository.findById(99);
+
+ assertEquals("Data not found", result, "Should return 'Data not found' for missing entries.");
+ }
+
+ @Test
+ void testDelete() {
+ repository.save(2, "To be deleted");
+ repository.delete(2);
+
+ String result = repository.findById(2);
+
+ assertEquals("Data not found", result, "Deleted data should not be retrievable.");
+ }
+
+ @Test
+ void testFindAll() {
+ repository.save(1, "First");
+ repository.save(2, "Second");
+
+ Map allData = repository.findAll();
+
+ assertEquals(2, allData.size(), "The repository should contain two items.");
+ assertTrue(allData.containsKey(1) && allData.containsKey(2), "Both keys should exist.");
+ }
+}
diff --git a/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataSourceServiceTest.java b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataSourceServiceTest.java
new file mode 100644
index 000000000000..1f861e45beb3
--- /dev/null
+++ b/polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataSourceServiceTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.polling;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.Map;
+import org.junit.jupiter.api.*;
+
+public class DataSourceServiceTest {
+
+ private DataRepository repository;
+ private DataSourceService service;
+
+ @BeforeEach
+ void setUp() {
+ repository = new DataRepository();
+ service = new DataSourceService(repository);
+ }
+
+ @Test
+ void testAddData() {
+ service.addData(1, "Test Data");
+
+ assertEquals("Test Data", repository.findById(1));
+ }
+
+ @Test
+ void testGetData() {
+ repository.save(1, "Test Data");
+
+ String result = service.getData(1);
+
+ assertEquals("Test Data", result, "The retrieved data should match.");
+ }
+
+ @Test
+ void testRemoveData() {
+ repository.save(2, "Some Data");
+
+ service.removeData(2);
+
+ assertEquals(
+ "Data not found", repository.findById(2), "Deleted data should not be retrievable.");
+ }
+
+ @Test
+ void testGetAllData() {
+ Map result = service.getAllData();
+
+ int size = result.size();
+ repository.save(1, "First");
+ repository.save(2, "Second");
+
+ Map result1 = service.getAllData();
+
+ assertEquals(size + 2, result.size(), "Should return all stored data.");
+ assertEquals("First", result.get(1), "Value for key 1 should be 'First'.");
+ assertEquals("Second", result.get(2), "Value for key 2 should be 'Second'.");
+ }
+}
diff --git a/polling-publisher/pom.xml b/polling-publisher/pom.xml
new file mode 100644
index 000000000000..7cf4c83bae7d
--- /dev/null
+++ b/polling-publisher/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+ 4.0.0
+
+ com.iluwatar
+ java-design-patterns
+ 1.26.0-SNAPSHOT
+
+
+ polling-publisher
+ pom
+
+
+ polling-service
+ subscriber-service
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring-boot.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+ ${spring-boot.version}
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring-boot.version}
+ test
+
+
+
+
+ org.springframework.kafka
+ spring-kafka
+ 3.3.2
+
+
+
+ org.springframework.kafka
+ spring-kafka-test
+ 3.3.2
+ test
+
+
+
+
+ org.springframework.boot
+ spring-boot
+ ${spring-boot.version}
+
+
+
+
+ javax.annotation
+ javax.annotation-api
+ 1.3.2
+
+
+
+ ch.qos.logback
+ logback-core
+ 1.5.18
+
+
+ ch.qos.logback
+ logback-classic
+ 1.5.18
+
+
+
+
+
diff --git a/polling-publisher/subscriber-service/etc/subscriber-service.urm.puml b/polling-publisher/subscriber-service/etc/subscriber-service.urm.puml
new file mode 100644
index 000000000000..02af47ddf261
--- /dev/null
+++ b/polling-publisher/subscriber-service/etc/subscriber-service.urm.puml
@@ -0,0 +1,2 @@
+@startuml
+@enduml
\ No newline at end of file
diff --git a/polling-publisher/subscriber-service/pom.xml b/polling-publisher/subscriber-service/pom.xml
new file mode 100644
index 000000000000..384f1b66c244
--- /dev/null
+++ b/polling-publisher/subscriber-service/pom.xml
@@ -0,0 +1,59 @@
+
+
+
+ 4.0.0
+
+ com.iluwatar
+ polling-publisher
+ 1.26.0-SNAPSHOT
+
+
+ subscriber-service
+ jar
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+
+
+
+ com.iluwatar.subscriber-service.App
+
+
+
+
+
+
+
+
+
+
diff --git a/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/App.java b/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/App.java
new file mode 100644
index 000000000000..b8dd8a23f4ec
--- /dev/null
+++ b/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/App.java
@@ -0,0 +1,37 @@
+/*
+ * 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.subscriber;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/** Polling-Publisher pattern paradigm. */
+@SpringBootApplication
+public class App {
+ public static void main(String[] args) {
+ SpringApplication.run(App.class, args);
+ }
+}
diff --git a/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/KafkaConsumer.java b/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/KafkaConsumer.java
new file mode 100644
index 000000000000..c159b467dcf1
--- /dev/null
+++ b/polling-publisher/subscriber-service/src/main/java/com/iluwatar/subscriber/KafkaConsumer.java
@@ -0,0 +1,48 @@
+/*
+ * 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.subscriber;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.stereotype.Service;
+
+/** Kafka consumer service to consume messages / updates. */
+@Service
+public class KafkaConsumer {
+
+ private static final Logger log = LoggerFactory.getLogger(KafkaConsumer.class);
+
+ @KafkaListener(topics = "updates", groupId = "subscriber-group")
+ public void listenUpdates(String message) {
+ log.info("[updates]: Received message: {}", message);
+ }
+
+ @KafkaListener(topics = "API", groupId = "subscriber-group")
+ public void listenApi(String message) {
+ log.info("[API]: Received message from /send : {}", message);
+ }
+}
diff --git a/polling-publisher/subscriber-service/src/main/resources/application.yml b/polling-publisher/subscriber-service/src/main/resources/application.yml
new file mode 100644
index 000000000000..16b8425f39b5
--- /dev/null
+++ b/polling-publisher/subscriber-service/src/main/resources/application.yml
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+server:
+ port: 8082
+
+spring:
+ kafka:
+ bootstrap-servers: localhost:9092 # Kafka broker address(es)
+ consumer:
+ group-id: subscriber-group
\ No newline at end of file
diff --git a/polling-publisher/subscriber-service/src/test/java/com/iluwatar/subscriber/AppTest.java b/polling-publisher/subscriber-service/src/test/java/com/iluwatar/subscriber/AppTest.java
new file mode 100644
index 000000000000..b03222d435e0
--- /dev/null
+++ b/polling-publisher/subscriber-service/src/test/java/com/iluwatar/subscriber/AppTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.subscriber;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class AppTest {
+
+ @Test
+ void subscriber() {
+ assertDoesNotThrow(() -> App.main(new String[] {}));
+ }
+}
diff --git a/pom.xml b/pom.xml
index 8337c97966da..b132277beb5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,6 +190,7 @@
partial-response
pipeline
poison-pill
+ polling-publisher
presentation-model
private-class-data
producer-consumer