Add notification service integration

Problem Context

The application uses WebFlux for reactive processing. A developer added a notification feature that calls an external service when orders are placed.

Expert
300 points

File Changes (1)

src/main/java/com/example/service/OrderNotificationService.java ADDED
@@ -0 +1 @@
1 +@Service
2 +@RequiredArgsConstructor
3 +public class OrderNotificationService {
4 + private final RestTemplate restTemplate;
5 +
6 + public Mono<Void> sendOrderConfirmation(Order order) {
7 + return Mono.fromRunnable(() -> {
8 + NotificationRequest request = NotificationRequest.builder()
9 + .userId(order.getUserId())
10 + .message("Order " + order.getId() + " confirmed")
11 + .build();
12 +
13 + int retries = 3;
14 + while (retries > 0) {
15 + try {
16 + restTemplate.postForObject(
17 + "https://notifications.example.com/send",
18 + request,
19 + Void.class);
20 + return;
21 + } catch (Exception e) {
22 + retries--;
23 + try {
24 + Thread.sleep(1000);
25 + } catch (InterruptedException ie) {
26 + Thread.currentThread().interrupt();
27 + }
28 + }
29 + }
30 + });
31 + }
32 +}
Login Required: You must be registered to submit reviews and receive AI feedback. Register or login to start reviewing!

Your Review

Tip: Be thorough! Consider security, performance, code quality, and best practices.
Review Tips
  • Look for security vulnerabilities (SQL injection, XSS, etc.)
  • Check for null pointer exceptions and error handling
  • Consider performance implications
  • Evaluate code maintainability and readability
  • Check for proper resource management
  • Look for logic errors or edge cases
Analyzing Your Review
Our AI is carefully evaluating your code review against best practices