feat: Microservice Messaging Pattern (#2681)#3420
feat: Microservice Messaging Pattern (#2681)#3420Mukul-Howale wants to merge 5 commits intoiluwatar:masterfrom
Conversation
Add initial project structure for microservices-messaging using Spring Boot. Includes Maven configuration with dependencies for Kafka, Lombok, and testing, as well as main application, test class, and application properties.
1. Added initial project structure for demonstrating the microservices messaging pattern. 2. Introduced service stubs (OrderService, InventoryService, PaymentService, NotificationService), a Message and MessageBroker class, and a main App entry point. 3. Added README and logging configuration.
1. Added the Message class with unique ID, content, and timestamp fields, and a toString method. 2. Implemented the MessageBroker class to support topic-based publish-subscribe messaging, including subscriber management, message publishing, and logging.
1. Added message handling logic to InventoryService, PaymentService, and NotificationService. 2. OrderService now publishes order events to a MessageBroker, and App demonstrates the messaging workflow. 3. Each service processes relevant order events and logs actions for demonstration purposes.
1. Enhanced the README with detailed explanations, real-world examples, Java code samples, and references for the Microservices Messaging pattern. 2. Added flowchart and sequence diagram images to illustrate the pattern.
PR SummaryImplements a microservices messaging pattern using a simple in-memory MessageBroker with topic-based publish/subscribe. Adds Changes
autogenerated by presubmit.ai |
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (5)
- 2a78490: Expand microservices messaging docs and add diagrams
- Enhanced the README with detailed explanations, real-world examples, Java code samples, and references for the Microservices Messaging pattern.
- Added flowchart and sequence diagram images to illustrate the pattern.
- 4258031: Implement messaging pattern for microservices
- Added message handling logic to InventoryService, PaymentService, and NotificationService.
- OrderService now publishes order events to a MessageBroker, and App demonstrates the messaging workflow. 3. Each service processes relevant order events and logs actions for demonstration purposes.
- 064ae70: Implement Message and MessageBroker classes
- Added the Message class with unique ID, content, and timestamp fields, and a toString method.
- Implemented the MessageBroker class to support topic-based publish-subscribe messaging, including subscriber management, message publishing, and logging.
- dfe54d7: Initialize microservices messaging pattern
- Added initial project structure for demonstrating the microservices messaging pattern.
- Introduced service stubs (OrderService, InventoryService, PaymentService, NotificationService), a Message and MessageBroker class, and a main App entry point.
- Added README and logging configuration.
- f6f2e2e: Initialize microservices-messaging Spring Boot project
Add initial project structure for microservices-messaging using Spring Boot. Includes Maven configuration with dependencies for Kafka, Lombok, and testing, as well as main application, test class, and application properties.
Files Processed (13)
- microservices-messaging/README.md (1 hunk)
- microservices-messaging/etc/microservices-messaging-flowchart.png (0 hunks)
- microservices-messaging/etc/microservices-messaging-sequence-diagram.png (0 hunks)
- microservices-messaging/pom.xml (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/App.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/InventoryService.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/Message.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/MessageBroker.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/NotificationService.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/OrderService.java (1 hunk)
- microservices-messaging/src/main/java/com/mukul/messaging/PaymentService.java (1 hunk)
- microservices-messaging/src/main/resources/logback.xml (1 hunk)
- microservices-messaging/src/test/java/com/mukul/messaging/MicroservicesMessagingApplicationTests.java (1 hunk)
Actionable Comments (4)
-
microservices-messaging/pom.xml [55-57]
best practice: "Build: missing SLF4J version property"
-
microservices-messaging/pom.xml [8-8]
best practice: "Config: Spring Boot parent version"
-
microservices-messaging/src/main/java/com/mukul/messaging/MessageBroker.java [26-29]
possible bug: "Possible bug: thread-safety in subscriber list"
-
microservices-messaging/src/test/java/com/mukul/messaging/MicroservicesMessagingApplicationTests.java [6-13]
best practice: "Test: SpringBootTest context loads without app"
Skipped Comments (2)
-
microservices-messaging/src/main/java/com/mukul/messaging/App.java [1-3]
enhancement: "Demo class not Spring Boot entry point"
-
microservices-messaging/README.md [75-89]
maintainability: "Documentation: type-safety and thread-safety in README example"
| <artifactId>slf4j-api</artifactId> | ||
| <version>${slf4j.version}</version> | ||
| </dependency> |
There was a problem hiding this comment.
Defining the SLF4J version via a property that isn't declared in the POM will cause a build failure. Either declare a <slf4j.version>...</slf4j.version> or hardcode a version here.
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>4.0.1</version> |
There was a problem hiding this comment.
The Spring Boot parent version 4.0.1 seems questionable and may not be compatible with your Java version 21. Please verify the correct Spring Boot parent version for your setup (e.g., a 3.x line) and ensure compatibility with Java 21.
| public void subscribe(String topic, Consumer<Message> handler) { | ||
| subscribers.computeIfAbsent(topic, k -> new ArrayList<>()).add(handler); | ||
| LOGGER.info("New subscriber added to topic: {}", topic); | ||
| } |
There was a problem hiding this comment.
The subscription path uses a non-thread-safe ArrayList inside a ConcurrentHashMap. If subscribe/publish happen concurrently, this could lead to race conditions. Consider using a thread-safe list implementation.
| @SpringBootTest | ||
| class MicroservicesMessagingApplicationTests { | ||
|
|
||
| @Test | ||
| void contextLoads() { | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
SpringBootTest is used here to load a Spring context, but this module currently lacks a Spring Boot application class. Either add a minimal Spring Boot app (annotated with @SpringBootApplication) or change this to a plain JUnit test.
|



Issue : #2681