|
87 | 87 | * @author Roman Samarev |
88 | 88 | * @author Soby Chacko |
89 | 89 | * @author Chris Bono |
| 90 | + * @author 2tsumo-hitori |
90 | 91 | */ |
91 | 92 | public class SimpleFunctionRegistry implements FunctionRegistry { |
92 | 93 | protected Log logger = LogFactory.getLog(this.getClass()); |
@@ -419,6 +420,8 @@ public class FunctionInvocationWrapper implements Function<Object, Object>, Cons |
419 | 420 |
|
420 | 421 | protected boolean wrapped; |
421 | 422 |
|
| 423 | + private boolean enableSplitting = false; |
| 424 | + |
422 | 425 | private final ThreadLocal<Message<Object>> unconvertedResult = new ThreadLocal<>(); |
423 | 426 |
|
424 | 427 | private PostProcessingFunction postProcessor; |
@@ -575,6 +578,14 @@ public Class<?> getRawInputType() { |
575 | 578 | return this.inputType == null ? null : FunctionTypeUtils.getRawType(this.inputType); |
576 | 579 | } |
577 | 580 |
|
| 581 | + public boolean isEnableSplitting() { |
| 582 | + return enableSplitting; |
| 583 | + } |
| 584 | + |
| 585 | + public void setEnableSplitting(boolean enableSplitting) { |
| 586 | + this.enableSplitting = enableSplitting; |
| 587 | + } |
| 588 | + |
578 | 589 | /** |
579 | 590 | * |
580 | 591 | */ |
@@ -815,6 +826,9 @@ private Object enrichInvocationResultIfNecessary(Object input, Object result) { |
815 | 826 | if (functionInvocationHelper != null && CloudEventMessageUtils.isCloudEvent(((Message) input))) { |
816 | 827 | result = functionInvocationHelper.postProcessResult(result, (Message) input); |
817 | 828 | } |
| 829 | + else if (this.enableSplitting && !FunctionTypeUtils.isCollectionOfMessage(this.outputType)) { |
| 830 | + result = ((Collection<?>) result).stream().map(it -> MessageBuilder.withPayload(it).copyHeaders(sanitizeHeaders(((Message) input).getHeaders())).build()).toList(); |
| 831 | + } |
818 | 832 | else if (!FunctionTypeUtils.isCollectionOfMessage(this.outputType)) { |
819 | 833 | result = MessageBuilder.withPayload(result).copyHeaders(this.sanitizeHeaders(((Message) input).getHeaders())).build(); |
820 | 834 | } |
@@ -1266,6 +1280,9 @@ else if (convertedOutput instanceof Message) { |
1266 | 1280 | else if (convertedOutput instanceof Collection && this.isOutputTypeMessage()) { |
1267 | 1281 | convertedOutput = this.convertMultipleOutputValuesIfNecessary(convertedOutput, ObjectUtils.isEmpty(contentType) ? null : contentType); |
1268 | 1282 | } |
| 1283 | + else if (convertedOutput instanceof Collection && this.isEnableSplitting()) { |
| 1284 | + convertedOutput = this.convertMultipleOutputValuesIfNecessary(convertedOutput, ObjectUtils.isEmpty(contentType) ? null : contentType); |
| 1285 | + } |
1269 | 1286 | else if (ObjectUtils.isArray(convertedOutput) && !(convertedOutput instanceof byte[])) { |
1270 | 1287 | convertedOutput = this.convertMultipleOutputValuesIfNecessary(convertedOutput, ObjectUtils.isEmpty(contentType) ? null : contentType); |
1271 | 1288 | } |
|
0 commit comments