-
-
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
Microservices pattern : Self-Registration #3245
base: master
Are you sure you want to change the base?
Conversation
PR SummaryThis PR implements a microservices self-registration pattern using Spring Boot, Eureka, and OpenFeign. It includes a Eureka server and two microservices (Greeting and Context) that register with Eureka and communicate with each other. The project also includes unit tests and health checks. 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 (4)
Files Processed (30)
- microservices-self-registration/README.md (1 hunk)
- microservices-self-registration/contextservice/.gitattributes (1 hunk)
- microservices-self-registration/contextservice/.gitignore (1 hunk)
- microservices-self-registration/contextservice/.mvn/wrapper/maven-wrapper.properties (1 hunk)
- microservices-self-registration/contextservice/application.log.2025-04-05.0.gz (0 hunks)
- microservices-self-registration/contextservice/mvnw (1 hunk)
- microservices-self-registration/contextservice/mvnw.cmd (1 hunk)
- microservices-self-registration/contextservice/pom.xml (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/ContextserviceApplication.java (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/client/GreetingServiceClient.java (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java (1 hunk)
- microservices-self-registration/contextservice/src/main/resources/application.yml (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java (1 hunk)
- microservices-self-registration/eurekaserver/.gitattributes (1 hunk)
- microservices-self-registration/eurekaserver/.gitignore (1 hunk)
- microservices-self-registration/eurekaserver/.mvn/wrapper/maven-wrapper.properties (1 hunk)
- microservices-self-registration/eurekaserver/mvnw (1 hunk)
- microservices-self-registration/eurekaserver/mvnw.cmd (1 hunk)
- microservices-self-registration/eurekaserver/pom.xml (1 hunk)
- microservices-self-registration/eurekaserver/src/main/java/com/learning/eurekaserver/EurekaserverApplication.java (1 hunk)
- microservices-self-registration/eurekaserver/src/main/resources/application.yml (1 hunk)
- microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java (1 hunk)
- microservices-self-registration/greetingservice/.gitattributes (1 hunk)
- microservices-self-registration/greetingservice/.gitignore (1 hunk)
- microservices-self-registration/greetingservice/.mvn/wrapper/maven-wrapper.properties (1 hunk)
- microservices-self-registration/greetingservice/application.log.2025-04-05.0.gz (0 hunks)
- microservices-self-registration/greetingservice/mvnw (1 hunk)
- microservices-self-registration/greetingservice/mvnw.cmd (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.
Add the new module to parent pom.xml, otherwise it won't be built by CI
microservices-self-registration/contextservice/.mvn/wrapper/maven-wrapper.properties
Outdated
Show resolved
Hide resolved
...gistration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java
Outdated
Show resolved
Hide resolved
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)
- 93c6653: Merge branch 'iluwatar:master' into master
Files Processed (5)
- microservices-self-registration/README.md (1 hunk)
- microservices-self-registration/contextservice/application.log.2025-04-05.0.gz (0 hunks)
- microservices-self-registration/contextservice/pom.xml (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java (1 hunk)
- microservices-self-registration/greetingservice/application.log.2025-04-05.0.gz (0 hunks)
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 (3)
- 030643b: Merge branch 'master' of https://github.com/naman-sriv/java-design-patterns
- 796b421: Merge branch 'master' of https://github.com/naman-sriv/java-design-patterns
- 13bc41f: pom.xml, clean up, java version update and slf4j logging added
Files Processed (5)
- microservices-self-registration/contextservice/application.log.2025-04-07.0.gz (0 hunks)
- microservices-self-registration/contextservice/pom.xml (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java (1 hunk)
- microservices-self-registration/eurekaserver/pom.xml (1 hunk)
- microservices-self-registration/greetingservice/application.log.2025-04-07.0.gz (0 hunks)
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)
- 20d34ec: pom files updated
Files Processed (2)
- microservices-self-registration/contextservice/pom.xml (1 hunk)
- microservices-self-registration/eurekaserver/pom.xml (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)
- c2c13ae: Merge branch 'iluwatar:master' into master
Files Processed (0)
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.
- Add microservices-self-registration to parent pom.xml. Otherwise it's not built by CI.
- Remove Maven wrappers
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)
- 17d019f: Merge branch 'iluwatar:master' into master
Files Processed (0)
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 (3)
- 142fe8b: Merge branch 'master' of https://github.com/naman-sriv/java-design-patterns
- 8b08728: Microservice-self-registration added to pom file
- 2bd955d: Removed children maven wrappers
Files Processed (2)
- microservices-self-registration/contextservice/application.log.2025-04-09.0.gz (0 hunks)
- microservices-self-registration/greetingservice/application.log.2025-04-09.0.gz (0 hunks)
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)
- d06d61e: POM file updated for self-registration
Files Processed (0)
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)
- aa788f0: pom file updated
Files Processed (0)
Actionable Comments (0)
Skipped Comments (0)
correction to mudule name
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
Files Processed (0)
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 (2)
- 7d0152b: Merge branch 'master' of https://github.com/naman-sriv/java-design-patterns
- 6b1c680: SonarQube comments addressed
Files Processed (4)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/controller/ContextController.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextserviceApplicationTests.java (1 hunk)
- microservices-self-registration/eurekaserver/src/test/java/com/learning/eurekaserver/EurekaserverApplicationTests.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
-
microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java [28-35]
enhancement: "Improve ContextControllerTest test robustness."
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)
- ab2c8ac: sonarqube comments on coverage addressed
Files Processed (3)
- microservices-self-registration/application.log.2025-04-09.0.gz (0 hunks)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/TestConfig.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
-
microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java [20-50]
best practice: "Use @WebMvcTest for unit tests."
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.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- c4b33cd: Code coverage for custom health checks
Files Processed (1)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java (1 hunk)
Actionable Comments (1)
-
microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java [40-59]
possible bug: "Flaky test due to time dependency."
Skipped Comments (0)
// Force performHealthCheck to return true (by time simulation - might be flaky) | ||
long currentTimeForTrue = System.currentTimeMillis(); | ||
while (currentTimeForTrue % 10000 >= 5000) { | ||
Thread.sleep(10); // Wait until time is in the "true" range | ||
currentTimeForTrue = System.currentTimeMillis(); | ||
} | ||
ReflectionTestUtils.invokeMethod(healthCheck, "performHealthCheck"); | ||
healthCheck.updateHealthStatus(); | ||
assertTrue((Boolean) ReflectionTestUtils.getField(healthCheck, "isHealthy"), "Health should be true"); | ||
|
||
// Force performHealthCheck to return false (by time simulation - might be flaky) | ||
long currentTimeForFalse = System.currentTimeMillis(); | ||
while (currentTimeForFalse % 10000 < 5000) { | ||
Thread.sleep(10); // Wait until time is in the "false" range | ||
currentTimeForFalse = System.currentTimeMillis(); | ||
} | ||
ReflectionTestUtils.invokeMethod(healthCheck, "performHealthCheck"); | ||
healthCheck.updateHealthStatus(); | ||
assertFalse((Boolean) ReflectionTestUtils.getField(healthCheck, "isHealthy"), "Health should be false"); | ||
} |
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.
The test relies on time-based conditions (lines 40-45 and 50-55), which can lead to flaky test results. Consider refactoring to remove the time dependency or use a mocking framework to simulate the behavior of performHealthCheck
.
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)
- edb73c1: changes for unit tests
Files Processed (3)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java (1 hunk)
- microservices-self-registration/eurekaserver/pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
-
microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java [26-29]
possible issue: "Improve health check simulation."
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)
- 84b6676: changes for unit tests
Files Processed (1)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
-
microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java [1-43]
enhancement: "Add negative test cases for health check."
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)
- fcf605d: changes to for code coverage improvement
Files Processed (5)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java (1 hunk)
- microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/client/GreetingServiceClient.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/ContextControllerTest.java (1 hunk)
- microservices-self-registration/contextservice/src/test/java/com/learning/contextservice/myCustomHealthCheckTest.java (1 hunk)
- microservices-self-registration/greetingservice/application.log.2025-04-11.0.gz (0 hunks)
Actionable Comments (0)
Skipped Comments (1)
-
microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java [26-29]
possible issue: "Improve health check simulation."
|
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.
Additionally, please remove the log archives such as:
microservices-self-registration/application.log.2025-04-09.0.gz
microservices-self-registration/contextservice/application.log.2025-04-05.0.gz
microservices-self-registration/contextservice/application.log.2025-04-07.0.gz
microservices-self-registration/contextservice/application.log.2025-04-09.0.gz
We don't need those stored in the repository.
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.4.4</version> | ||
<relativePath/> </parent> | ||
<groupId>com.learning</groupId> |
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 groupId com.iluwatar
@Component("myCustomHealthCheck") | ||
public class MyCustomHealthCheck implements HealthIndicator { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(MyCustomHealthCheck.class); |
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 annotation @slf4j for logging
|
||
boolean performHealthCheck() { | ||
boolean current = System.currentTimeMillis() % 10000 < 5000; // Simulate fluctuating health | ||
log.debug("Performing health check, current status: {}", current); |
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 debug-level logging not to spam the output
<properties> | ||
<java.version>21</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> <configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
</configuration> | ||
</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 think you can use the maven-compiler-plugin from the parent pom.xml, so all this can be left out. This helps in maintenance work.
Pull Request Template
What does this PR do?
Implemented the Microservices Self-Registration pattern using Spring Boot (3.4.4) and Eureka. This PR includes the Eureka Server setup and two microservices (Greeting and Context) that register with Eureka and communicate using OpenFeign. Key Spring Cloud dependencies include Eureka Discovery Client, Eureka Server, and OpenFeign.