Skip to content

Comments

feat: Microservice Messaging Pattern (#2681)#3420

Closed
Mukul-Howale wants to merge 5 commits intoiluwatar:masterfrom
Mukul-Howale:feat-microservice-messaging-pattern
Closed

feat: Microservice Messaging Pattern (#2681)#3420
Mukul-Howale wants to merge 5 commits intoiluwatar:masterfrom
Mukul-Howale:feat-microservice-messaging-pattern

Conversation

@Mukul-Howale
Copy link

Issue : #2681

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.
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

PR Summary

Implements a microservices messaging pattern using a simple in-memory MessageBroker with topic-based publish/subscribe. Adds Message, OrderService (producer) and InventoryService, PaymentService, NotificationService (consumers). App demonstrates the workflow. Expanded README with explanations, flowchart and sequence diagram images. Includes Maven config for dependencies (Spring Boot, Kafka, Lombok), logging config, and tests.

Changes

File Summary
microservices-messaging/README.md Expanded README to explain the Microservices Messaging pattern with real-world examples, Java code samples, flowchart and sequence diagram references, and guidance on when to use the pattern.
microservices-messaging/etc/microservices-messaging-flowchart.png New flowchart illustrating the messaging flow between producer and consumers.
microservices-messaging/etc/microservices-messaging-sequence-diagram.png New sequence diagram showing the order topic and consumer interactions.
microservices-messaging/pom.xml Configures Spring Boot with Kafka, Lombok, and test dependencies; Java 21; build plugins for Lombok and Spring Boot.
microservices-messaging/src/main/java/com/mukul/messaging/App.java Demo app wires a MessageBroker, subscribes InventoryService, PaymentService, and NotificationService to order-topic, and runs a sequence of order lifecycle events.
microservices-messaging/src/main/java/com/mukul/messaging/InventoryService.java Consumes Messages, updates or restores inventory based on order events, with simulated delays and logging.
microservices-messaging/src/main/java/com/mukul/messaging/Message.java Defines Message with id, content, timestamp, with constructor and toString.
microservices-messaging/src/main/java/com/mukul/messaging/MessageBroker.java Implements topic-based publish/subscribe, manages subscribers, publishes messages, and logs activity.
microservices-messaging/src/main/java/com/mukul/messaging/NotificationService.java Sends order-related notifications for Created/Updated/Cancelled events with simulated delays.
microservices-messaging/src/main/java/com/mukul/messaging/OrderService.java Publishes Order Created/Updated/Cancelled messages to order-topic via MessageBroker.
microservices-messaging/src/main/java/com/mukul/messaging/PaymentService.java Handles payment events: process on created, refund on cancelled, with simulated latency.
microservices-messaging/src/main/resources/logback.xml Configures console logging at INFO level with a com.iluwatar.messaging logger.
microservices-messaging/src/test/java/com/mukul/messaging/MicroservicesMessagingApplicationTests.java Spring Boot context load test ensuring application context initializes.

autogenerated by presubmit.ai

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (5)
  • 2a78490: Expand microservices messaging docs and add diagrams
  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.
  • 4258031: Implement messaging pattern for microservices
  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.
  • 064ae70: Implement Message and MessageBroker classes
  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.
  • dfe54d7: Initialize microservices messaging pattern
  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.
  • 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"

Comment on lines +55 to +57
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

Choose a reason for hiding this comment

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

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>

Choose a reason for hiding this comment

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

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.

Comment on lines +26 to +29
public void subscribe(String topic, Consumer<Message> handler) {
subscribers.computeIfAbsent(topic, k -> new ArrayList<>()).add(handler);
LOGGER.info("New subscriber added to topic: {}", topic);
}

Choose a reason for hiding this comment

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

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.

Comment on lines +6 to +13
@SpringBootTest
class MicroservicesMessagingApplicationTests {

@Test
void contextLoads() {
}

}

Choose a reason for hiding this comment

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

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.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant