WIP:reconnect
authorKai Moritz <kai@juplo.de>
Mon, 11 Mar 2024 17:32:46 +0000 (18:32 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 16 Mar 2024 09:14:06 +0000 (10:14 +0100)
src/test/java/de/juplo/kafka/chat/backend/TestListener.java

index e5b2529..3f7fb9d 100644 (file)
@@ -12,7 +12,9 @@ import org.springframework.http.codec.ServerSentEvent;
 import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
 
+import java.time.Duration;
 import java.util.*;
 
 
@@ -52,7 +54,8 @@ public class TestListener
         })
         .doOnNext(message -> list.add(message))
         .doOnComplete(() -> log.info("{} was completed!", chatRoom))
-        .doOnError(throwalbe -> log.error("{} failed: {}", chatRoom, throwalbe));
+        .doOnError(throwalbe -> log.error("{} failed: {}", chatRoom, throwalbe))
+        .thenMany(Flux.defer(() -> receiveMessages(chatRoom)));
   }
 
   Flux<ServerSentEvent<String>> receiveServerSentEvents(ChatRoomInfoTo chatRoom)
@@ -64,7 +67,8 @@ public class TestListener
             chatRoom.getId())
         .accept(MediaType.TEXT_EVENT_STREAM)
         .retrieve()
-        .bodyToFlux(SSE_TYPE);
+        .bodyToFlux(SSE_TYPE)
+        .retryWhen(Retry.fixedDelay(15, Duration.ofSeconds(1)));
   }