From 1d38c149354cfb1f863e022bdd879fdb080c0e1e Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 13 Mar 2018 16:06:20 -0400 Subject: [PATCH] GH-719: Container Factory: Add replyPostProcessor Resolves https://github.com/spring-projects/spring-amqp/issues/719 Add `replyPostProcessor` to the container factory. * Polishing - support an array of MPPs for consistency with other places. * Polishing - PR Comments --- ...bstractRabbitListenerContainerFactory.java | 20 +++++++++- .../AbstractAdaptableMessageListener.java | 37 +++++++++++++------ .../EnableRabbitIntegrationTests.java | 5 +++ .../core/RabbitTemplateIntegrationTests.java | 2 +- src/reference/asciidoc/amqp.adoc | 2 + src/reference/asciidoc/whats-new.adoc | 2 + 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java index 81f3d71f..5c5f576f 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; import org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener; import org.springframework.amqp.support.ConsumerTagStrategy; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.beans.BeansException; @@ -103,6 +104,8 @@ public abstract class AbstractRabbitListenerContainerFactory { + m.getMessageProperties().getHeaders().put("replyMPPApplied", true); + return m; + }); return factory; } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java index 260fe567..0709908b 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java @@ -1382,7 +1382,7 @@ public class RabbitTemplateIntegrationTests { return message.toUpperCase(); } }); - messageListener.setReplyPostProcessor(new GZipPostProcessor()); + messageListener.setBeforeSendReplyPostProcessors(new GZipPostProcessor()); container.setMessageListener(messageListener); container.setReceiveTimeout(100); container.afterPropertiesSet(); diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 5b52a1ea..cf736bc3 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -1850,6 +1850,8 @@ It is possible to customize the listener container factory to use per annotation The default is only required if at least one endpoint is registered without a specific container factory. See the javadoc for full details and examples. +The container factories provide methods for adding `MessagePostProcessor` s that will be applied after receiving messages (before invoking the listener) and before sending replies. + If you prefer XML configuration, use the `` element; any beans annotated with `@RabbitListener` will be detected. For `SimpleRabbitListenerContainer` s: diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 74cff063..c34b564b 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -141,6 +141,8 @@ You can now set the `concurrency` of the listener container at the annotation le You can now set the `autoStartup` property of the listener container at the annotation level, overriding the default setting in the container factory. +You can now set after receive and before send (reply) `MessagePostProcessor` s in the `RabbitListener` container factories. + See <> for more information. Starting with _version 2.0.3_, one of the `@RabbitHandler` s on a class-level `@RabbitListener` can be designated as the default.