Skip to content

Honor the listener error handler for synchronous AMQP 1.0 failures - #3786

Merged
artembilan merged 2 commits into
spring-projects:mainfrom
sharanggupta:amqp-adapter-sync-error-handler
Oct 28, 2026
Merged

artembilan merged 2 commits into
spring-projects:mainfrom
sharanggupta:amqp-adapter-sync-error-handler

Conversation

@sharanggupta

Copy link
Copy Markdown
Contributor

RabbitAmqpMessageListenerAdapter.onAmqpMessage() wraps a listener exception in a ListenerExecutionFailedException and throws it without calling handleException(), so a @RabbitListener(errorHandler = ...) and returnExceptions are ignored for synchronous failures on an AMQP 1.0 container; the async path already delegates through asyncFailure(). This routes synchronous failures through handleException() like onMessage() does.

`RabbitAmqpMessageListenerAdapter.onAmqpMessage()` wraps any listener
exception and throws it, so the `RabbitListenerErrorHandler` and the
`returnExceptions` option of a `@RabbitListener` are only honored for
`Future`/`Mono` failures, where `asyncFailure()` delegates to
`handleException()`.

* Delegate synchronous failures to `handleException()` as `onMessage()` does,
rethrowing a `ReplyFailureException` unchanged
* Add `RabbitAmqpMessageListenerAdapterTests` covering the error handler
invocation, the acknowledgment on a null result and a rethrown error

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@artembilan artembilan added this to the 4.2.0 milestone Oct 28, 2026
Signed-off-by: Artem Bilan <artem.bilan@broadcom.com>
@artembilan
artembilan enabled auto-merge (squash) October 28, 2026 18:23
@artembilan
artembilan merged commit 695a7ee into spring-projects:main Oct 28, 2026
3 checks passed
spring-builds pushed a commit that referenced this pull request Oct 28, 2026
Fixes: #3786

`RabbitAmqpMessageListenerAdapter.onAmqpMessage()` wraps any listener
exception and throws it, so the `RabbitListenerErrorHandler` and the
`returnExceptions` option of a `@RabbitListener` are only honored for
`Future`/`Mono` failures, where `asyncFailure()` delegates to
`handleException()`.

* Delegate synchronous failures to `handleException()` as `onMessage()` does,
rethrowing a `ReplyFailureException` unchanged
* Add `RabbitAmqpMessageListenerAdapterTests` covering the error handler
invocation, the acknowledgment on a null result and a rethrown error

* Fix `@since` to `4.0.7` in the `RabbitAmqpMessageListenerAdapterTests`

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Co-authored-by: Artem Bilan <artem.bilan@broadcom.com>

(cherry picked from commit 695a7ee)
artembilan pushed a commit that referenced this pull request Oct 28, 2026
Fixes: #3786

`RabbitAmqpMessageListenerAdapter.onAmqpMessage()` wraps any listener
exception and throws it, so the `RabbitListenerErrorHandler` and the
`returnExceptions` option of a `@RabbitListener` are only honored for
`Future`/`Mono` failures, where `asyncFailure()` delegates to
`handleException()`.

* Delegate synchronous failures to `handleException()` as `onMessage()` does,
rethrowing a `ReplyFailureException` unchanged
* Add `RabbitAmqpMessageListenerAdapterTests` covering the error handler
invocation, the acknowledgment on a null result and a rethrown error

* Fix `@since` to `4.0.7` in the `RabbitAmqpMessageListenerAdapterTests`

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Co-authored-by: Artem Bilan <artem.bilan@broadcom.com>

(cherry picked from commit 695a7ee)

# Conflicts:
#	spring-rabbitmq-client/src/main/java/org/springframework/amqp/rabbitmq/client/listener/RabbitAmqpMessageListenerAdapter.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants