Skip to content

Apply afterReceivePostProcessors to batch and plain listeners - #3790

Merged
artembilan merged 2 commits into
spring-projects:mainfrom
sharanggupta:amqp-listener-post-processors-all-paths
Oct 28, 2026
Merged

artembilan merged 2 commits into
spring-projects:mainfrom
sharanggupta:amqp-listener-post-processors-all-paths

Conversation

@sharanggupta

Copy link
Copy Markdown
Contributor

RabbitAmqpListenerContainer.setAfterReceivePostProcessors() promises the processors run after every reception, but the container only passes them to a RabbitAmqpMessageListenerAdapter, which applies them on its single-message path. A batch @RabbitListener and any other MessageListener get the messages unprocessed, so for example a decompressing processor is skipped. This applies the processors in the container for the plain listener path and for each message of a batch; the adapter's own single-message handling is unchanged.

*
* @since 4.2
*/
public class RabbitAmqpListenerContainerPostProcessorTests {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.
Same here.
Stop "mocking", please.
Try real broker tests first.

@artembilan artembilan added this to the 4.2.0 milestone Oct 28, 2026

@artembilan artembilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, rebase and resolve conflicts:

This branch has conflicts that must be resolved

Use the [web editor](https://github.com/spring-projects/spring-amqp/pull/3790/conflicts) or the command line to resolve conflicts before continuing.

    spring-rabbitmq-client/src/test/java/org/springframework/amqp/rabbitmq/client/listener/RabbitAmqpListenerTests.java

`RabbitAmqpListenerContainer` only hands its `afterReceivePostProcessors` to a
`RabbitAmqpMessageListenerAdapter`, which applies them for single messages.
Batch listeners and any other `MessageListener` receive the messages
unprocessed, although the Javadoc promises the processors run after every
reception.

* Apply the processors in the container for the plain listener path and for
each message of a batch
* Add `RabbitAmqpListenerContainerPostProcessorTests` for both paths

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
Replace the mock-based test with `RabbitAmqpListenerTests` cases that consume
a plain message and a batch from a real broker and check the header set by an
`afterReceivePostProcessors` entry.

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
@sharanggupta
sharanggupta force-pushed the amqp-listener-post-processors-all-paths branch from 78200e1 to 43aee1b Compare October 28, 2026 19:29
@artembilan
artembilan enabled auto-merge (squash) October 28, 2026 19:32
@artembilan
artembilan disabled auto-merge October 28, 2026 20:11
@artembilan
artembilan merged commit 090135d into spring-projects:main Oct 28, 2026
3 checks passed
spring-builds pushed a commit that referenced this pull request Oct 28, 2026
Fixes: #3790

`RabbitAmqpListenerContainer` only hands its `afterReceivePostProcessors` to a
`RabbitAmqpMessageListenerAdapter`, which applies them for single messages.
Batch listeners and any other `MessageListener` receive the messages
unprocessed, although the Javadoc promises the processors run after every
reception.

* Apply the processors in the container for the plain listener path and for
each message of a batch
* Add `RabbitAmqpListenerContainerPostProcessorTests` for both paths

* Test the post processors against a real broker

Replace the mock-based test with `RabbitAmqpListenerTests` cases that consume
a plain message and a batch from a real broker and check the header set by an
`afterReceivePostProcessors` entry.

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>

(cherry picked from commit 090135d)
artembilan pushed a commit that referenced this pull request Oct 28, 2026
Fixes: #3790

`RabbitAmqpListenerContainer` only hands its `afterReceivePostProcessors` to a
`RabbitAmqpMessageListenerAdapter`, which applies them for single messages.
Batch listeners and any other `MessageListener` receive the messages
unprocessed, although the Javadoc promises the processors run after every
reception.

* Apply the processors in the container for the plain listener path and for
each message of a batch
* Add `RabbitAmqpListenerContainerPostProcessorTests` for both paths

* Test the post processors against a real broker

Replace the mock-based test with `RabbitAmqpListenerTests` cases that consume
a plain message and a batch from a real broker and check the header set by an
`afterReceivePostProcessors` entry.

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>

(cherry picked from commit 090135d)

# Conflicts:
#	spring-rabbitmq-client/src/test/java/org/springframework/amqp/rabbitmq/client/listener/RabbitAmqpListenerTests.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