INT-4437: Scatter-Gather: reinstate replyChannel

JIRA: https://jira.spring.io/browse/INT-4437

The `ScatterGatherHandler` overrides a `replyChannel` header for the
scatter message to its internal queue and doesn't reinstate the original
`replyChannel` header when producer a gather result message

* Rebuild gather result message with population a proper `replyChannel`
header from the request message and removing a `gatherResultChannel`
header

**Cherry-pick to 5.0.3 and 4.3.x**

Polishing
This commit is contained in:
Artem Bilan
2018-03-20 16:32:49 -04:00
committed by Gary Russell
parent ed563b9f3f
commit 64a37381e0
3 changed files with 13 additions and 5 deletions

View File

@@ -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.
@@ -147,7 +147,11 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i
Message<?> gatherResult = gatherResultChannel.receive(this.gatherTimeout);
if (gatherResult != null) {
return gatherResult;
return getMessageBuilderFactory()
.fromMessage(gatherResult)
.removeHeader(GATHER_RESULT_CHANNEL)
.setHeader(MessageHeaders.REPLY_CHANNEL, requestMessage.getHeaders().getReplyChannel())
.build();
}
return null;

View File

@@ -52,12 +52,14 @@
<!--Sync scenario-->
<gateway id="gateway" default-request-channel="gatewayAuction"/>
<gateway id="gateway" default-request-channel="gatewayAuction" default-reply-timeout="10000" />
<scatter-gather input-channel="gatewayAuction" scatter-channel="auctionChannel">
<scatter-gather input-channel="gatewayAuction" output-channel="bridgeChannel" scatter-channel="auctionChannel">
<gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"/>
</scatter-gather>
<bridge input-channel="bridgeChannel"/>
<chain input-channel="scatterGatherWithinChain" output-channel="output">
<scatter-gather scatter-channel="auctionChannel"/>
<splitter/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 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.
@@ -37,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Artem Bilan
* @author Gary Russell
* @since 4.1
*/
@ContextConfiguration
@@ -81,6 +82,7 @@ public class ScatterGatherTests {
@Test
public void testGatewayScatterGather() {
Message<?> bestQuoteMessage = this.gateway.exchange(new GenericMessage<String>("foo"));
assertNotNull(bestQuoteMessage);
Object payload = bestQuoteMessage.getPayload();
assertThat(payload, instanceOf(List.class));
assertThat(((List<?>) payload).size(), greaterThanOrEqualTo(1));