【问题标题】:Making multiple calls to the same service in context xml在上下文 xml 中多次调用同一服务
【发布时间】:2016-02-15 20:34:55
【问题描述】:

我有一个 REST 服务,我从我的 spring 上下文文件中调用它,并且根据收到的响应,我可以继续其余的处理,或者使用不同的 uri_variable 再次调用相同的服务。 下面是我的上下文文件-

<int:chain id="Search" input-channel="inputChannel" output-channel="channel1">

<int:header-enricher>
    <int:header name="accept" value="application/xml" overwrite="true"/>
    <int:header name="Authorization" method="getAuth" ref="Auth"/>
 </int:header-enricher>

    <int-xml:xpath-header-enricher>
        <int-xml:header name="medId" xpath-expression="/MedicineFamily/medicineId/text()" evaluation-type="STRING_RESULT" />
 </int-xml:xpath-header-enricher>

<int-http:outbound-gateway id="ServiceGateway" http-method="GET" reply-timeout="1000" 
    expected-response-type="java.lang.String" url="https://#{environment['dataservice.address']}:#{environment['dataservice.port']}/#{environment['dataservice.paths.medId']}"
    mapped-request-headers="accept,Authorization" mapped-response-headers="medId" error-handler="ErrorHandler">
    <int-http:uri-variable name="med_id" expression="headers['medId']"/>
 </int-http:outbound-gateway>

 <int:transformer  ref="PharmacyBean" method ="formMed"/>
</int:chain>

在这里,我使用出站网关调用数据服务,其中 uri 变量作为从另一个服务调用接收到的 medId。现在根据这个服务的结果和在转换器中完成的处理,我可能需要再次调用这个服务,但这次使用不同的 uri 变量。

我怎样才能发回一个不同的变量并用这个新的 uri 变量再次调用这个服务? 另外,如果我返回了多个 medId 并且我想为其中的每一个调用该服务,我该如何循环调用该服务? 谢谢!

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    在网关之后添加路由器,并根据需要路由回网关。当多个medIds时,路由到一个splitter;如果您需要在拆分器之后重新组装结果,请使用聚合器。

    在这种情况下,您可能会发现在splitter-&gt;http-&gt;aggregator 流中添加第二个网关更容易;否则路由器中的条件可能会变得复杂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多