INT-4244: Optimize JpaOutboundGateway for Message
JIRA: https://jira.spring.io/browse/INT-4244 The `JpaOutboundGateway` returns a whole `Message` for reply copying request headers. Building the reply a `AbstractMessageProducingHandler` uses `MessageBuilder` to create a new `Message` with all request headers because of `shouldCopyRequestHeaders() == true` * To avoid some overhead with new `Message` and `MessageBuilder` for nothing, just return a JPA result as is and let super class to build the Message * Optimize all reply producers to return `MessageBuilder` to the super `handleMessage()` process * Return the whole `gatherResult` `Message<?>` from the `ScatterGatherHandler` to have ability to transfer reply headers as well * Mark `DelayHandler` as `shouldCopyRequestHeaders() return false` since it doesn't modify Message and returns it as is after delay
This commit is contained in:
committed by
Gary Russell
parent
752fe0356f
commit
df9593a528
@@ -75,6 +75,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 1.0.3
|
||||
*/
|
||||
|
||||
@@ -234,6 +235,11 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
|
||||
return releaseHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldCopyRequestHeaders() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if 'requestMessage' wasn't delayed before
|
||||
* ({@link #releaseMessageAfterDelay} and {@link DelayHandler.DelayedMessageWrapper}).
|
||||
@@ -243,10 +249,8 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
|
||||
* @param requestMessage - the Message which may be delayed.
|
||||
* @return - {@code null} if 'requestMessage' is delayed,
|
||||
* otherwise - 'payload' from 'requestMessage'.
|
||||
*
|
||||
* @see #releaseMessage
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
boolean delayed = requestMessage.getPayload() instanceof DelayedMessageWrapper;
|
||||
@@ -260,8 +264,7 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
|
||||
}
|
||||
|
||||
// no delay
|
||||
Object payload = requestMessage.getPayload();
|
||||
return delayed ? ((DelayedMessageWrapper) payload).getOriginal().getPayload() : payload;
|
||||
return delayed ? ((DelayedMessageWrapper) requestMessage.getPayload()).getOriginal() : requestMessage;
|
||||
}
|
||||
|
||||
private long determineDelayForMessage(Message<?> message) {
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i
|
||||
|
||||
Message<?> gatherResult = gatherResultChannel.receive(this.gatherTimeout);
|
||||
if (gatherResult != null) {
|
||||
return gatherResult.getPayload();
|
||||
return gatherResult;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -417,7 +417,9 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler
|
||||
targetHeaders.put(header, value);
|
||||
}
|
||||
}
|
||||
return this.getMessageBuilderFactory().withPayload(targetPayload).copyHeaders(targetHeaders).build();
|
||||
return getMessageBuilderFactory()
|
||||
.withPayload(targetPayload)
|
||||
.copyHeaders(targetHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user