java-design-patterns icon indicating copy to clipboard operation
java-design-patterns copied to clipboard

#2673: Microservice pattern: Polling publisher

Open quantdevv opened this issue 8 months ago • 2 comments

Pull Request Template

What does this PR do?

This PR introduces a microservice-based architecture that includes a polling-publisher and a subscriber-service communicating via Apache Kafka. It demonstrates an in-memory data flow mechanism using Kafka topics.

The PR includes:

  • Kafka producer REST endpoint for sending messages
  • Kafka consumer that listens automatically and processes messages
  • Spring Boot configuration for both microservices
  • Initial testing and local setup for message flow validation

Fixes #2673

Type of change

  • [x] New feature (non-breaking change)
  • [x] Documentation update

How has this been tested?

  • Manually tested Kafka message publishing via /send endpoint
  • Verified automatic listening and processing in subscriber microservice
  • Logs and terminal output confirm end-to-end communication

Additional context

Both microservices are designed for local Kafka communication using port 9092. Make sure the Kafka broker is running before testing

quantdevv avatar Apr 06 '25 12:04 quantdevv

PR Summary

This PR introduces a microservice-based architecture with a polling publisher and subscriber service communicating via Apache Kafka. It demonstrates an in-memory data flow mechanism using Kafka topics, including a Kafka producer REST endpoint, a Kafka consumer, Spring Boot configuration for both microservices, and initial testing.

Changes

File Summary
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/App.java Updated license header in the App.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Cart.java Updated license header in the Cart.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartController.java Updated license header in the CartController.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartRepository.java Updated license header in the CartRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryCartRepository.java Updated license header in the InMemoryCartRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryOrderRepository.java Updated license header in the InMemoryOrderRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryProductRepository.java Updated license header in the InMemoryProductRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Order.java Updated license header in the Order.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderController.java Updated license header in the OrderController.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderRepository.java Updated license header in the OrderRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Product.java Updated license header in the Product.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ProductRepository.java Updated license header in the ProductRepository.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ShoppingCartService.java Updated license header in the ShoppingCartService.java file.
clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/package-info.java Updated license header in the package-info.java file.
clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/AppTest.java Updated license header in the AppTest.java file.
clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/CartControllerTest.java Updated license header in the CartControllerTest.java file.
polling-publisher/README.md New file: README for the polling publisher project, describing the project structure, tech stack, and setup instructions.
polling-publisher/etc/polling-publisher.urm.puml New file: Empty plantuml file for the polling publisher.
polling-publisher/polling-service/README.md New file: README for the polling service, explaining its functionality and structure.
polling-publisher/polling-service/etc/polling-service.urm.puml New file: Empty plantuml file for the polling service.
polling-publisher/polling-service/pom.xml New file: POM file for the polling service module, defining dependencies and build configurations.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java New file: Main application class for the polling service, using Spring Boot.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java New file: Repository class for managing in-memory data, using a HashMap.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java New file: Service class for interacting with the data source, adding, retrieving, and removing data.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java New file: Producer class for sending messages to Kafka, using Spring Kafka.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java New file: Controller class for handling REST endpoints, including a health check and a message sending endpoint.
polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java New file: Scheduler class for periodically polling the data source and publishing updates to Kafka.
polling-publisher/polling-service/src/main/resources/application.yml New file: Configuration file for the polling service, specifying server port and Kafka connection details.
polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java New file: Test class for the polling service application, verifying the main method execution.
polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java New file: Test class for the DataRepository, covering save, findById, delete, and findAll methods.

autogenerated by presubmit.ai

github-actions[bot] avatar Apr 06 '25 12:04 github-actions[bot]

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
64.1% Coverage on New Code (required ≥ 80%)
E Security Rating on New Code (required ≥ A)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

sonarqubecloud[bot] avatar Apr 06 '25 13:04 sonarqubecloud[bot]

Closed due to inactivity. Thank you for the contribution.

iluwatar avatar May 29 '25 18:05 iluwatar

Hi @iluwatar , yeah i was busy with some other stuff due to high priority... will submit PR again & will close it soon.

quantdevv avatar May 29 '25 18:05 quantdevv

Hi @iluwatar , I addressed all the review-comments & made all the changes..

please review PR: https://github.com/iluwatar/java-design-patterns/pull/3292#issue-3107649814

Thanks 👍

quantdevv avatar Jun 01 '25 17:06 quantdevv