diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/BaseRabbitListenerContainerFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/BaseRabbitListenerContainerFactory.java index 339c7e08..51e01020 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/BaseRabbitListenerContainerFactory.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/BaseRabbitListenerContainerFactory.java @@ -17,6 +17,7 @@ package org.springframework.amqp.rabbit.config; import java.util.Arrays; +import java.util.function.Function; import org.aopalliance.aop.Advice; @@ -26,6 +27,7 @@ import org.springframework.amqp.rabbit.listener.MessageListenerContainer; import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; import org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint; import org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener; +import org.springframework.amqp.rabbit.listener.adapter.ReplyPostProcessor; import org.springframework.amqp.utils.JavaUtils; import org.springframework.lang.Nullable; import org.springframework.retry.RecoveryCallback; @@ -54,6 +56,8 @@ public abstract class BaseRabbitListenerContainerFactory replyPostProcessorProvider; + @Override public abstract C createListenerContainer(RabbitListenerEndpoint endpoint); @@ -108,6 +112,17 @@ public abstract class BaseRabbitListenerContainerFactory replyPostProcessorProvider) { + this.replyPostProcessorProvider = replyPostProcessorProvider; + } + protected void applyCommonOverrides(@Nullable RabbitListenerEndpoint endpoint, C instance) { if (endpoint != null) { // endpoint settings overriding default factory settings JavaUtils.INSTANCE @@ -130,6 +145,11 @@ public abstract class BaseRabbitListenerContainerFactory rpp); return factory; } + @Bean + ReplyPostProcessor rpp() { + return (in, out) -> out; + } + @Bean public SimpleRabbitListenerContainerFactory jsonListenerContainerFactory() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 67a3d851..ff6edd75 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -3144,6 +3144,22 @@ public ReplyPostProcessor echoCustomHeader() { ---- ==== +Starting with version 3.0, you can configure the post processor on the container factory instead of on the annotation. + +==== +[source, java] +---- +factory.setReplyPostProcessorProvider(id -> (req, resp) -> { + resp.getMessageProperties().setHeader("myHeader", req.getMessageProperties().getHeader("myHeader")); + return resp; +}); +---- +==== + +The `id` parameter is the listener id. + +A setting on the annotation will supersede the factory setting. + The `@SendTo` value is assumed as a reply `exchange` and `routingKey` pair that follows the `exchange/routingKey` pattern, where one of those parts can be omitted. The valid values are as follows: diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 912926c3..a55a2d40 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -37,7 +37,10 @@ When setting the container factory `consumerBatchEnabled` to `true`, the `batchL See <> for more infoprmation. `MessageConverter` s can now return `Optional.empty()` for a null value; this is currently implemented by the `Jackson2JsonMessageConverter`. -See <> for more information. +See <> for more information + +You can now configure a `ReplyPostProcessor` via the container factory rather than via a property on `@RabbitListener`. +See <> for more information. ==== Connection Factory Changes