使用多个参数构造URL的Spring Integration网关

时间:2018-08-03 16:31:40

标签: spring-integration

在当前模型中,我们有一个REST端点,该端点获取请求正文,并基于该端点创建一个jms文本消息并将其发送到JMS队列,

TextMessage outMessage = session.createTextMessage(messagePayloadText);
           ..          
outMessage.setStringProperty("clientType", clientType);
outMessage.setStringProperty("DYNAMIC", dynaHeader);

在上面的代码中,需要DYNAMIC来帮助我创建我们的网址

<int:chain input-channel="gCStatusInChannel" output-channel="headerFilterChannel">
    <int:header-enricher>           
        <int:header name="Api-Key" value="B8872853E8B"></int:header>
        <int:header name="Accept" value="application/json" /> 
        <int:header name="Content-Type" value="application/json" />         
    </int:header-enricher>      
    <int-http:outbound-gateway  
           url="https://i-zaie.sr13.tst.bst/ia-zaaie/rest/search/v2/cReference/{cref}"
           http-method="PUT"               
           header-mapper="headerMapper" 
           expected-response-type="java.lang.String"
           encode-uri="false"
           request-factory="sslFactory">               
     <int-http:uri-variable name="cref" expression="headers['DYNAMIC']" />                 
    </int-http:outbound-gateway>
    <int:object-to-string-transformer></int:object-to-string-transformer>
</int:chain>

一切都适用于此模型。现在我要使用网关而不是JMS

新代码

<int:gateway id="gService"
    service-interface="n.d.lr.eai.gw.GGateway"
    default-reply-channel="dest-channel"
    default-request-timeout="5000" default-reply-timeout="5000">
    <int:method name="vCreateSignal" request-channel="vCreateSignalInChannel"/> ...

问题:  我可以在网关中使用以下方法吗?

public String vCreateSignal(String caseDat, String dynamic);

我应该怎么做才能启用

<int:chain input-channel="gCStatusInChannel"...
..>

获取标题['DYNAMIC']值并继续。

1 个答案:

答案 0 :(得分:1)

是的,您可以这样做。您只需要在该@Header("DYNAMIC")参数中添加一个dynamic

public String vCreateSignal(String caseDat, @Header("DYNAMIC") String dynamic);

当您调用此网关的方法时,您只需指定一个参数,它将被映射到适当的标头,并且所有参数:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints-chapter.html#gateway-mapping