2

I wanted to retry in case of any exception from the service. But when using retryWhen am getting exception java.lang.IllegalStateException: UnicastProcessor allows only a single Subscriber.

Without retry, its working fine

Flux.window(10)
    .flatMap(
          windowedFlux -> 
         webclient.post().uri(url)
        .body(BodyInserters.fromPublisher(windowedFlux, Request.class))
        .exchange()
        .doOnNext(ordRlsResponse -> {
                     if( ordRlsResponse.statusCode().is2xxSuccessful()) {                               
                        Mono<ResponseEntity<Response>> response = ordRlsResponse.toEntity(Response.class);              
                        //doing some processing here             
                     }           
                     else {                  
                        throw new CustomeException(errmsg);              
                     }

        }).retryWhen(retryStrategy)).subscribe();

And my retryStrategy is defined like:

Retry retryStrategy = Retry.fixedDelay((long)5, Duration.ofSeconds((long)5)) 
                         .filter(exception -> exception instanceof CustomeException) 
                         .doAfterRetry( exception -> log.info("Retry attempted"))
Abhinaba Chakraborty
  • 3,488
  • 2
  • 16
  • 37
  • you are somehow returning a UnicastProcessor in your code, so please post more of your code. – Toerktumlare Jul 30 '20 at 15:56
  • Can you share the `retryStrategy`? – vins Jul 30 '20 at 16:11
  • Retry retryStrategy = Retry.fixedDelay((long)5, Duration.ofSeconds((long)5)) .filter(exception -> exception instanceof CustomeException) .doAfterRetry( exception -> log.info("Retry attempted")). – Revathy Satheesh Jul 30 '20 at 16:17
  • @Thomas Andolf `Flux.window(10) .flatMap( windowedFlux -> webclient.post().uri(url) .body(BodyInserters.fromPublisher(windowedFlux, Request.class)) .exchange() .doOnNext(ordRlsResponse -> { if( ordRlsResponse.statusCode().is2xxSuccessful()) { Mono> response = ordRlsResponse.toEntity(Response.class); //doing some processing here } else { throw new CustomeException(errmsg); } }).retryWhen(retryStrategy)).subscribe();` – Revathy Satheesh Jul 30 '20 at 16:32
  • Dont post it here, update your question – Toerktumlare Jul 30 '20 at 18:49
  • please update your question so that it shows what `doOnNext` returns – Toerktumlare Jul 30 '20 at 18:55
  • Same with flux.window(...).filter(...).flatMap(...). Internally, some methods produce an UnicastProcessor which is single shot only. In some cases an additional .map(Flux::cache) might be suitable. – Tires Jul 02 '21 at 19:38

0 Answers0