Skip to content

Error handler for async RabbitListeners (Mono, Future, suspend) not acking message when ErrorHandler returns null #3247

@jensbaitingerbosch

Description

@jensbaitingerbosch

In what version(s) of Spring AMQP are you seeing this issue?

3.2.8

Describe the bug

When having an async Rabbit listener which throws an exception and the error handler returns null (assuming that the exception had been somehow mitigated (e.g. triggering a retry), the message is not acked but 'hangs' unacked for all eternity (or until the rabbit server times out).

In contrast using the same logic with a sync listener, the message is acked.

To Reproduce

Send a message to an the queue theQueue and the message stays anacked. Send a message to theOtherQueue and the message is consumed.

@Component
class Consumer() {

    @RabbitListener(queues = ["theQueue"], errorHandler = "errorHandler" )
    suspend fun consumeRabbitMessage(message: Message): Unit? {
        throw RuntimeException("something went wrong while consuming the message")
    }

       @RabbitListener(queues = ["theOtherQueue"], errorHandler = "errorHandler" )
   fun consumeRabbitMessageSync(message: Message): Unit? {
        throw RuntimeException("something went wrong while consuming the message")
    }
}

@Component
class ErrorHandler : RabbitListenerErrorHandler {
    override fun handleError(
        msg: Message?,
        ch: Channel?,
        msg2: org.springframework.messaging.Message<*>?,
        ex: ListenerExecutionFailedException?
    ): Any? {

        //asume the error was handled internally
        return null
    }
}

Expected behavior

The message should be acked (analog behaviour to a sync listener)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions