Skip to content

Commit bcf4402

Browse files
artembilangaryrussell
authored andcommitted
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
1 parent f44eb37 commit bcf4402

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -147,7 +147,11 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
147147

148148
Message<?> gatherResult = gatherResultChannel.receive(this.gatherTimeout);
149149
if (gatherResult != null) {
150-
return gatherResult;
150+
return getMessageBuilderFactory()
151+
.fromMessage(gatherResult)
152+
.removeHeader(GATHER_RESULT_CHANNEL)
153+
.setHeader(MessageHeaders.REPLY_CHANNEL, requestMessage.getHeaders().getReplyChannel())
154+
.build();
151155
}
152156

153157
return null;

spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests-context.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@
5252

5353
<!--Sync scenario-->
5454

55-
<gateway id="gateway" default-request-channel="gatewayAuction"/>
55+
<gateway id="gateway" default-request-channel="gatewayAuction" default-reply-timeout="10000" />
5656

57-
<scatter-gather input-channel="gatewayAuction" scatter-channel="auctionChannel">
57+
<scatter-gather input-channel="gatewayAuction" output-channel="bridgeChannel" scatter-channel="auctionChannel">
5858
<gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"/>
5959
</scatter-gather>
6060

61+
<bridge input-channel="bridgeChannel"/>
62+
6163
<chain input-channel="scatterGatherWithinChain" output-channel="output">
6264
<scatter-gather scatter-channel="auctionChannel"/>
6365
<splitter/>

spring-integration-core/src/test/java/org/springframework/integration/scattergather/config/ScatterGatherTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737

3838
/**
3939
* @author Artem Bilan
40+
* @author Gary Russell
4041
* @since 4.1
4142
*/
4243
@ContextConfiguration
@@ -81,6 +82,7 @@ public void testDistribution() {
8182
@Test
8283
public void testGatewayScatterGather() {
8384
Message<?> bestQuoteMessage = this.gateway.exchange(new GenericMessage<String>("foo"));
85+
assertNotNull(bestQuoteMessage);
8486
Object payload = bestQuoteMessage.getPayload();
8587
assertThat(payload, instanceOf(List.class));
8688
assertThat(((List<?>) payload).size(), greaterThanOrEqualTo(1));

0 commit comments

Comments
 (0)