0

I have a consumer:

@Bean
public Function<Flux<Message<byte[]>>, Mono<Void>> myReactiveConsumer() {
  return flux ->
      flux.doOnNext(this::processMessage)
          .doOnError(this::isRepetableError, ?message -> sendToTimeoutQueue(message)?)
          .doOnError(this::allOtherErrors, ?message -> sendToDlq(message)?)
          .then();
}

In case of deterministic error I want the message to be sent to dead letter queue, but if the error isn't deterministic, I want the message to be sent to specific timeout queue (depending on how many times it has failed).

I have tried configuring RetryTemplate but it doesn't seem to give me enough information to redirect the message to different queue

@StreamRetryTemplate
public RetryTemplate myRetryTemplate() {
  return new RetryTemplate(...init);
}

Also configuring it through yaml file allows me to almost do what is needed but not exactly.

A solution like this seems good but I was unable to get it to work as spring cloud uses different beans.

How can I implement this retry logic?

  • Seems that logic I'm interested in is in this method but I can't overwrite it in a reasonable manner: RabbitMessageChannelBinder.getErrorMessageHandler https://github.com/spring-cloud/spring-cloud-stream/blob/3178464f14e360672cec5926751bde9df318f0ff/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java#L668 – Kristjan Kiolein Aug 16 '22 at 22:39
  • 1
    Framework provided error handling only applies to imperative functions. Reactive functions are not supported for reasons that framework has no view into the logic of the reactive functions. Unlike imperative function that are message handlers and are invoked on each message reactive functions are "initialization functions". They are executed only once at the startup to connect the fluxes/monos. from that point on the logic and all the error handling is in the reactive API. – Oleg Zhurakousky Aug 17 '22 at 12:35

0 Answers0