Skip to content

Commit 13bc41f

Browse files
committed
pom.xml, clean up, java version update and slf4j logging added
1 parent afc7862 commit 13bc41f

File tree

7 files changed

+38
-56
lines changed

7 files changed

+38
-56
lines changed
Binary file not shown.

microservices-self-registration/contextservice/pom.xml

+8-19
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,22 @@
1313
<version>0.0.1-SNAPSHOT</version>
1414
<name>contextservice</name>
1515
<description>contextservice</description>
16-
<url/>
17-
<licenses>
18-
<license/>
19-
</licenses>
20-
<developers>
21-
<developer/>
22-
</developers>
23-
<scm>
24-
<connection/>
25-
<developerConnection/>
26-
<tag/>
27-
<url/>
28-
</scm>
16+
2917
<properties>
30-
<java.version>17</java.version>
18+
<java.version>21</java.version>
3119
<spring-cloud.version>2024.0.1</spring-cloud.version>
3220
</properties>
3321
<dependencies>
3422
<dependency>
3523
<groupId>org.springframework.boot</groupId>
3624
<artifactId>spring-boot-starter-web</artifactId>
3725
</dependency>
26+
<dependency>
27+
<groupId>org.projectlombok</groupId>
28+
<artifactId>lombok</artifactId>
29+
<version>1.18.38</version>
30+
<scope>provided</scope>
31+
</dependency>
3832
<dependency>
3933
<groupId>org.springframework.cloud</groupId>
4034
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
@@ -52,11 +46,6 @@
5246
<artifactId>spring-boot-starter-test</artifactId>
5347
<scope>test</scope>
5448
</dependency>
55-
<dependency>
56-
<groupId>org.springframework.boot</groupId>
57-
<artifactId>spring-boot-starter-test</artifactId>
58-
<scope>test</scope>
59-
</dependency>
6049
</dependencies>
6150
<dependencyManagement>
6251
<dependencies>

microservices-self-registration/contextservice/src/main/java/com/learning/contextservice/MyCustomHealthCheck.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.learning.contextservice;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.springframework.boot.actuate.health.Health;
46
import org.springframework.boot.actuate.health.HealthIndicator;
57
import org.springframework.scheduling.annotation.Scheduled;
@@ -8,28 +10,31 @@
810
@Component("myCustomHealthCheck")
911
public class MyCustomHealthCheck implements HealthIndicator {
1012

13+
private static final Logger log = LoggerFactory.getLogger(MyCustomHealthCheck.class);
14+
1115
private volatile boolean isHealthy = true;
1216

1317
@Scheduled(fixedRate = 5000) // Run every 5 seconds
1418
public void updateHealthStatus() {
1519
// Perform checks here to determine the current health
1620
// For example, check database connectivity, external service availability, etc.
17-
boolean currentHealth = performHealthCheck();
18-
isHealthy = currentHealth;
19-
System.out.println("Updated health status: " + isHealthy); // For logging
21+
isHealthy = performHealthCheck();
22+
log.info("Update health status : {}", isHealthy);
2023
}
2124

2225
private boolean performHealthCheck() {
23-
// Replace this with your actual health check logic
24-
// For demonstration, let's toggle the status every few runs
25-
return System.currentTimeMillis() % 10000 < 5000; // Simulate fluctuating health
26+
boolean current = System.currentTimeMillis() % 10000 < 5000; // Simulate fluctuating health
27+
log.debug("Performing health check, current status: {}", current);
28+
return current; // Simulate fluctuating health
2629
}
2730

2831
@Override
2932
public Health health() {
3033
if (isHealthy) {
34+
log.info("Health check successful, service is UP");
3135
return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
3236
} else {
37+
log.warn("Health check failed, service is DOWN");
3338
return Health.down().withDetail("error", "Scheduled health checks failed").build();
3439
}
3540
}

microservices-self-registration/eurekaserver/pom.xml

+2-14
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,9 @@
1313
<version>0.0.1-SNAPSHOT</version>
1414
<name>eurekaserver</name>
1515
<description>eurekaserver</description>
16-
<url/>
17-
<licenses>
18-
<license/>
19-
</licenses>
20-
<developers>
21-
<developer/>
22-
</developers>
23-
<scm>
24-
<connection/>
25-
<developerConnection/>
26-
<tag/>
27-
<url/>
28-
</scm>
16+
2917
<properties>
30-
<java.version>17</java.version>
18+
<java.version>21</java.version>
3119
<spring-cloud.version>2024.0.1</spring-cloud.version>
3220
</properties>
3321
<dependencies>
Binary file not shown.

microservices-self-registration/greetingservice/pom.xml

+9-15
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,23 @@
1313
<version>0.0.1-SNAPSHOT</version>
1414
<name>greetingservice</name>
1515
<description>greetingservice</description>
16-
<url/>
17-
<licenses>
18-
<license/>
19-
</licenses>
20-
<developers>
21-
<developer/>
22-
</developers>
23-
<scm>
24-
<connection/>
25-
<developerConnection/>
26-
<tag/>
27-
<url/>
28-
</scm>
16+
2917
<properties>
30-
<java.version>17</java.version>
18+
<java.version>21</java.version>
3119
<spring-cloud.version>2024.0.1</spring-cloud.version>
3220
</properties>
3321
<dependencies>
3422
<dependency>
3523
<groupId>org.springframework.boot</groupId>
3624
<artifactId>spring-boot-starter-web</artifactId>
3725
</dependency>
38-
<dependency>
26+
<dependency>
27+
<groupId>org.projectlombok</groupId>
28+
<artifactId>lombok</artifactId>
29+
<version>1.18.38</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
<dependency>
3933
<groupId>org.springframework.cloud</groupId>
4034
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
4135
</dependency>

microservices-self-registration/greetingservice/src/main/java/com/learning/greetingservice/MyCustomHealthCheck.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.learning.greetingservice;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.springframework.boot.actuate.health.Health;
45
import org.springframework.boot.actuate.health.HealthIndicator;
56
import org.springframework.scheduling.annotation.Scheduled;
67
import org.springframework.stereotype.Component;
78

89
@Component("myCustomHealthCheck")
10+
@Slf4j
911
public class MyCustomHealthCheck implements HealthIndicator {
1012

1113
private volatile boolean isHealthy = true;
@@ -16,20 +18,24 @@ public void updateHealthStatus() {
1618
// For example, check database connectivity, external service availability, etc.
1719
boolean currentHealth = performHealthCheck();
1820
isHealthy = currentHealth;
19-
System.out.println("Updated health status: " + isHealthy); // For logging
21+
log.info("Updated health status : {}", isHealthy);
2022
}
2123

2224
private boolean performHealthCheck() {
2325
// Replace this with your actual health check logic
2426
// For demonstration, let's toggle the status every few runs
25-
return System.currentTimeMillis() % 10000 < 5000; // Simulate fluctuating health
27+
boolean current = System.currentTimeMillis() % 10000 < 5000;
28+
log.debug("Performing health check, current status: {}", current);
29+
return current; // Simulate fluctuating health
2630
}
2731

2832
@Override
2933
public Health health() {
3034
if (isHealthy) {
35+
log.info("Health check successful, service is UP");
3136
return Health.up().withDetail("message", "Service is running and scheduled checks are OK").build();
3237
} else {
38+
log.warn("Health check failed, service is DOWN");
3339
return Health.down().withDetail("error", "Scheduled health checks failed").build();
3440
}
3541
}

0 commit comments

Comments
 (0)