Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
合并两个http请求的结果(spring集成)_Spring_Spring Integration - Fatal编程技术网

合并两个http请求的结果(spring集成)

合并两个http请求的结果(spring集成),spring,spring-integration,Spring,Spring Integration,我正在努力做到以下几点: 发出两个http请求(getData和getMetadata),然后将结果合并到如下负载:{res1:getDataResult,res2:getMetadataResult},然后将其传递到“resultChannel” <int:header-enricher input-channel="request" output-channel="getData"> <int:header name="prop" value="1"/> &l

我正在努力做到以下几点:

发出两个http请求(getData和getMetadata),然后将结果合并到如下负载:{res1:getDataResult,res2:getMetadataResult},然后将其传递到“resultChannel”

<int:header-enricher input-channel="request" output-channel="getData">
    <int:header name="prop" value="1"/>
</int:header-enricher>

<int-http:outbound-gateway
        request-channel="getData"
        url-expression="'https://x.y.z/{param1}'"
        http-method="GET"
        reply-channel="aggregate"
        expected-response-type="java.util.HashMap"
        request-factory="restFactory">
    <int-http:uri-variable name="param1" expression="payload.param1"/>
</int-http:outbound-gateway>

<int-http:outbound-gateway
        request-channel="getData"
        url-expression="'https://x.y.z/{param2}'"
        http-method="GET"
        reply-channel="aggregate"
        expected-response-type="java.util.HashMap"
        request-factory="restFactory">
    <int-http:uri-variable name="param2" expression="payload.param2"/>
</int-http:outbound-gateway>

<int:aggregator
        release-strategy-expression="size() == 2"
        input-channel="aggregate"
        output-channel="resultChannel"
        correlation-strategy-expression="headers['prop']"
        expire-groups-upon-completion="true">
</int:aggregator>
<!---->

<int:channel id="resultChannel" />

作为输入,我有一个有效负载,其中包含必须用于请求的param1和param2

使用

您需要一个关联策略(将两个回复分组);发布策略可能非常简单,如
发布策略expression=“size()==2”

如果在两个请求中都将头设置为某个值,比如说
foo
,则使用
correlation strategy expression=“headers['foo']”“

聚合器将两个回复配对,并将它们作为一个集合发布;然后,您可以使用
生成最终结果


您可以重复使用相同的相关性值,只要设置
在完成时过期组=“true”
。否则,具有已发布相关性的邮件将被丢弃。

加里,这很有帮助。我已经更新了这个问题。我有一个不同的问题-聚合器在这种配置下似乎不工作。“不工作”没有多大帮助。打开调试日志记录并通过流跟踪消息。如果您仍然无法理解,则需要显示更多配置。既然两个网关都从同一个通道消费,那么您将需要使用一个发布子通道,这样两个网关都可以获得消息。(但我看你已经明白了)。帮助