Closed EnriqueWood closed 6 months ago
Due to the default way Micronaut Kafka currently handles reactive return values (it optimistically continues the poll() loop and auto commits offsets without blocking), the only way I see that we can combine error strategies with reactive return values without breaking things would be to also require the @Blocking
annotation on the reactive method. I was hoping that worked already, but it does not. I will put together a PR to fix that.
Expected Behavior
When using the
@KafkaListener
annotation with@ErrorStrategy(value = ErrorStrategyValue.RETRY_ON_ERROR)
, it is expected that the listener will retry the specified number of times (retryCount
) with a certain delay (retryDelay
) between retries when an exception is thrown. This behavior should be consistent regardless of whether the method returns a reactive type (e.g.,Mono
) or a non-reactive type.Actual Behaviour
The retry mechanism works as expected for methods that do not return a reactive type. However, for methods returning a reactive type, such as
Mono
, the retry mechanism does not activate upon encountering exceptions. Instead of retrying, the error is logged, and no further action is taken, which leads to message processing being halted without retries.Steps To Reproduce
@KafkaListener
class with two methods listening to two different topics: one returning a non-reactive type and another returning a reactive type (Mono
), both configured with an@ErrorStrategy
that specifies retry behavior.Code sample A WebhookServiceListener class is defined with two methods annotated with @Topic. One method, workingRetry, returns a non-reactive type and demonstrates the expected retry mechanism when an exception occurs. The other method, nonWorkingRetry, returns a reactive type (Mono
Logs Upon Injecting a Message into the
working_retry
Topic:Logs Upon Injecting a Message into the
non_working_retry
Topic:These logs evidence that while the retry mechanism works as expected for the workingRetry method (non-reactive return type), it does not engage for the nonWorkingRetry method (reactive return type), leading to a failure in retry attempts upon errors.
Environment Information
Micronaut Version: 4.3.1 (latest at this time) Micronaut Kafka Version: 5.3.0 JDK Version: OpenJDK 17.0.1 Operating System: macOS Sonoma 14.3.1
Example Application
No response
Version
4.3.1