-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
#2673: Microservice pattern: Polling publisher #3243
base: master
Are you sure you want to change the base?
Conversation
…cture, README.md & App.java
…ifferent operation & prepared initial skeleton
… & implemented polling-service microservice
…te dependency from pom.xml & added required one
PR SummaryThis 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
autogenerated by presubmit.ai |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ LGTM!
Review Summary
Commits Considered (19)
- 059f292: added polling-publisher module in pom.xml
- 84d08f0: added scope before class definition in Test classes & removed duplicate dependency from pom.xml & added required one
- 5e3c951: synced with remote branch
- 24b87bb: added description on both application.yaml file
- 4eeb011: updated all README.md
- 5aa46ac: added new listener for other topic
- a59362c: Fixed topic name
- 1b3d933: Fixed subscriber-service & updated pom.xml
- 46abbfb: Fixed Kafka bug & added a controller to send message using API
- a7cc2c3: implemented subscriber microservice using kafkaConsumer
- a7497c4: implemented Data repository, DataSource Service & added unittest-case & implemented polling-service microservice
- 78f1ea9: resolved dependency & structured classes
- 931ab84: added unit test-case for DataSourceService class
- bb065d3: added entry point for subscriber service & unit test-case
- 4988d2e: subscriber-service implementation
- a2b8743: fixed checkstyle errors
- 0051d3f: polling-publisher service implementation
- c4e9276: added two service polling service & publisher service to handle two different operation & prepared initial skeleton
- faf0a12: added new microservice pattern polling-publisher, created folder structure, README.md & App.java
Files Processed (30)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/App.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Cart.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartController.java (2 hunks)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryCartRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryOrderRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryProductRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Order.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderController.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Product.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ProductRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ShoppingCartService.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/package-info.java (1 hunk)
- clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/AppTest.java (1 hunk)
- clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/CartControllerTest.java (1 hunk)
- polling-publisher/README.md (1 hunk)
- polling-publisher/etc/polling-publisher.urm.puml (1 hunk)
- polling-publisher/polling-service/README.md (1 hunk)
- polling-publisher/polling-service/etc/polling-service.urm.puml (1 hunk)
- polling-publisher/polling-service/pom.xml (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/App.java (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataRepository.java (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/DataSourceService.java (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/KafkaProducer.java (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingController.java (1 hunk)
- polling-publisher/polling-service/src/main/java/com/iluwatar/polling/PollingScheduler.java (1 hunk)
- polling-publisher/polling-service/src/main/resources/application.yml (1 hunk)
- polling-publisher/polling-service/src/test/java/com/iluwatar/polling/AppTest.java (1 hunk)
- polling-publisher/polling-service/src/test/java/com/iluwatar/polling/DataRepositoryTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ LGTM!
Review Summary
Commits Considered (1)
- 8c50536: Merge branch 'master' into issue-2673
Files Processed (16)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/App.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Cart.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartController.java (2 hunks)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/CartRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryCartRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryOrderRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/InMemoryProductRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Order.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderController.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/OrderRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/Product.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ProductRepository.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/ShoppingCartService.java (1 hunk)
- clean-architecture/src/main/java/com/iluwatar/cleanarchitecture/package-info.java (1 hunk)
- clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/AppTest.java (1 hunk)
- clean-architecture/src/test/java/com/iluwatar/cleanarchitecture/CartControllerTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)
|
@@ -0,0 +1,47 @@ | |||
# Polling Publisher-Subscriber Microservice Pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md has a specific format. See https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute
// Start a separate thread to add data every 3 seconds | ||
new Thread( | ||
() -> { | ||
Random random = new Random(); | ||
while (true) { | ||
try { | ||
Thread.sleep(3000); // Add data every 3 seconds | ||
int id = random.nextInt(100); // Random ID | ||
String value = "Auto-Data-" + id; | ||
this.addData(id, value); | ||
System.out.println("🔵 Data Added: " + id + " -> " + value); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
break; | ||
} | ||
} | ||
}) | ||
.start(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid busy-waiting loops. Perhaps use ScheduledExecutorService or similar...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Lombok's @slf4j for logging
<properties> | ||
<java.version>21</java.version> | ||
<spring.boot.version>3.4.4</spring.boot.version> | ||
</properties> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these. Use the versions from parent pom.xml.
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api --> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.junit.jupiter</groupId>--> | ||
<!-- <artifactId>junit-jupiter-api</artifactId>--> | ||
<!-- <version>5.10.1</version>--> | ||
<!-- <scope>test</scope>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.junit.jupiter</groupId>--> | ||
<!-- <artifactId>junit-jupiter-engine</artifactId>--> | ||
<!-- <version>5.9.2</version>--> | ||
<!-- <scope>test</scope>--> | ||
<!-- </dependency>--> | ||
<!-- <dependency>--> | ||
<!-- <groupId>org.springframework.boot</groupId>--> | ||
<!-- <artifactId>spring-boot-dependencies</artifactId>--> | ||
<!-- <version>${spring.boot.version}</version>--> | ||
<!-- <type>pom</type>--> | ||
<!-- <scope>import</scope>--> | ||
<!-- </dependency>--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-inline</artifactId> | ||
<version>5.2.0</version> | ||
<scope>test</scope> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if Spring Boot already contains a version of mockito...
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>1.5.18</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.5.18</version> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if Spring Boot already contains a version of logback...
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<!-- <artifactId>maven-assembly-plugin</artifactId>--> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>21</source> | ||
<target>21</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need these plugins specified here. They should come from the parent pom.xml
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:
Fixes #2673
Type of change
How has this been tested?
Additional context
Both microservices are designed for local Kafka communication using port 9092. Make sure the Kafka broker is running before testing