【问题标题】:Spring Integration gateway with multiple parameters to construct urlSpring集成网关,多参数构造url
【发布时间】:2018-08-03 16:31:40
【问题描述】:

在当前模型中,我们有一个 REST 端点,它获取 requestbody,在此基础上创建一条 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"...
..>

获取 headers['DYNAMIC'] 值并继续。

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    是的,你可以这样做。你只需要在dynamic 参数中添加一个@Header("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

    【讨论】:

    • 这没有帮助,完全不可读。请使用完整的堆栈跟踪编辑您的问题。顺便说一句,我看不出它与&lt;gateway&gt; 问题有什么关系...
    • 解决方案有效。错误请求是外部服务问题。
    猜你喜欢
    • 1970-01-01
    • 2012-04-05
    • 2012-09-21
    • 2012-05-21
    • 2018-06-15
    • 2014-07-24
    • 1970-01-01
    • 2019-03-01
    • 2014-06-08
    相关资源
    最近更新 更多