• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wistefan / tmforum-api / #49

29 Sep 2023 06:20AM UTC coverage: 67.488% (-4.3%) from 71.815%
#49

push

web-flow
Notifications (#23)

* Squashed commits

* Added cache invalidation for entity deletion

* Updated error message

618 of 618 new or added lines in 86 files covered. (100.0%)

2794 of 4140 relevant lines covered (67.49%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/src/main/java/org/fiware/tmforum/common/notification/NotificationSender.java
1
package org.fiware.tmforum.common.notification;
2

3
import io.github.resilience4j.core.IntervalFunction;
4
import io.github.resilience4j.reactor.retry.RetryOperator;
5
import io.github.resilience4j.retry.Retry;
6
import io.github.resilience4j.retry.RetryConfig;
7
import io.github.resilience4j.retry.RetryRegistry;
8
import io.micronaut.context.annotation.Bean;
9
import io.micronaut.http.HttpHeaders;
10
import io.micronaut.http.HttpRequest;
11
import io.micronaut.http.HttpResponse;
12
import io.micronaut.http.client.HttpClient;
13
import lombok.RequiredArgsConstructor;
14
import lombok.extern.slf4j.Slf4j;
15
import reactor.core.publisher.Mono;
16

17
import java.util.List;
18

19
@RequiredArgsConstructor
×
20
@Bean
21
@Slf4j
×
22
public class NotificationSender {
23
    private final HttpClient httpClient;
24

25
    private static final RetryRegistry RETRY_REGISTRY = RetryRegistry.of(RetryConfig.custom()
×
26
            .maxAttempts(10)
×
27
            .intervalFunction(IntervalFunction.ofExponentialBackoff())
×
28
            .failAfterMaxAttempts(true)
×
29
            .build());
×
30

31
    private Mono<HttpResponse<Object>> sendToClient(Notification notification) {
32
        HttpRequest<?> req = HttpRequest.POST(notification.callback(), notification.event())
×
33
                .header(HttpHeaders.CONTENT_TYPE, "application/json");
×
34
        return Mono.fromDirect(this.httpClient.exchange(req, Object.class));
×
35
    }
36

37
    public void sendNotifications(List<Notification> notifications) {
38
        notifications
×
39
                .forEach(notification -> {
×
40
                    Retry retry = RETRY_REGISTRY
×
41
                            .retry(String.valueOf(notification.hashCode()));
×
42
                    sendToClient(notification)
×
43
                            .transformDeferred(RetryOperator.of(retry))
×
44
                            .doOnError(e -> log.warn("Was not able to deliver notification {}.", notification, e))
×
45
                            .subscribe();
×
46
                });
×
47
    }
×
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc