春季集成:一个人可以从标头浓度内调用网关吗?

发布于 2025-02-07 08:54:20 字数 1035 浏览 2 评论 0原文

我需要拨打通往网关的许多电话,然后将退货有效载荷放入标题。这些 Gateway 调用实际上是向有链条后面的通道发送消息。目前看起来像这样:

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

<int:channel id            = "call_api_b" />
<int:chain   input-channel = "call_api_b" >
    ...
</int:chain>
<int:gateway request-channel="call_api_a" />

<int:header-enricher>
    <int:header name="a" expression="payload" />
</int:header-enricher>

<int:gateway request-channel="call_api_b" />

<int:header-enricher>
    <int:header name="b" expression="payload" />
</int:header-enricher>

是否有一种优雅的方式将通话嵌入到标头enricher内部的网关?

类似:

<int:header-enricher>
    <int:header name="a">
        <int:gateway request-channel="call_api_a" />
    </int:header>
</int:header-enricher>

我知道上述不起作用,但给人一种我想实现的意识。

感谢任何指示和最好的问候。

-aljo

I need to make a number of calls to gateways and to then place the return payloads into headers. These gateway calls are really sending a message to a channel behind which there is a chain. It currently looks like this:

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

<int:channel id            = "call_api_b" />
<int:chain   input-channel = "call_api_b" >
    ...
</int:chain>
<int:gateway request-channel="call_api_a" />

<int:header-enricher>
    <int:header name="a" expression="payload" />
</int:header-enricher>

<int:gateway request-channel="call_api_b" />

<int:header-enricher>
    <int:header name="b" expression="payload" />
</int:header-enricher>

Is there an elegant way to embed the call to the gateway inside of the header-enricher?

Something like:

<int:header-enricher>
    <int:header name="a">
        <int:gateway request-channel="call_api_a" />
    </int:header>
</int:header-enricher>

I know that the above doesn't work but gives the sense of what I'd like to achieve.

Thanks for any pointers and best regards.

-aljo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

゛清羽墨安 2025-02-14 08:54:20

不是&lt; gateway&gt;,而是这样:

<int:header-enricher>
    <int:header name="a"  ref="myGateway" method="gatewayMethod"/>
</int:header-enricher>

&lt; gateway&gt;是基于某些服务接口的bean。
您只需指向该Bean的&lt; header&gt;定义及其使用有效负载或消息的方法。

文档中有一些解释: https://docs.spring.io/spring-integration/docs/current/referent/referent/html/message-transformation.html#header-enricher

Not <gateway>, but like this:

<int:header-enricher>
    <int:header name="a"  ref="myGateway" method="gatewayMethod"/>
</int:header-enricher>

The <gateway> is bean based on some service interface.
You just point in the <header> definition to that bean and its method to be called against your payload or message.

There is some explanation in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#header-enricher

走过海棠暮 2025-02-14 08:54:20

看起来“附加网关定义”是进行此操作的方式。谢谢 @Artem-Bilan,指向我指向正确的方向。

我想直接从标头enricher打电话给我的链条通道。
如果我的链条通道是:

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

定义Java中的某个位置添加您的网关接口。

package com.app.wonderful;

@FunctionalInterface
public interface MyChainChannelGatewayMethod {
    Message<?> callChainChannel(Message<?> message) throws MessageException; 
}

定义指向您的链条通道的网关:

<int:gateway default-request-channel = "call_api_a"
             id                      = "call_api_a_GW"
             service-interface.      = "com.app.wonderful.MyChainChannelGatewayMethod" />

然后,您可以从标头式Enricher中的Spel表达式在线拨打网关:

<int:header-enricher >
    <int:header name="a"  expression="@call_api_a_GW(#root).payload" />
</int:header>

为我做的技巧。再次感谢。

It looks like the "additional gateway definition" is the way to go on this one. Thanks, @artem-bilan, for pointing me in the right direction.

I want to call to my chain-channel directly from a header-enricher.
If my chain-channel is:

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

Define somewhere in the Java add your gateway interface.

package com.app.wonderful;

@FunctionalInterface
public interface MyChainChannelGatewayMethod {
    Message<?> callChainChannel(Message<?> message) throws MessageException; 
}

Define a gateway that points to your chain-channel:

<int:gateway default-request-channel = "call_api_a"
             id                      = "call_api_a_GW"
             service-interface.      = "com.app.wonderful.MyChainChannelGatewayMethod" />

Then you can call your gateway in-line from the SpEL expression in the header-enricher:

<int:header-enricher >
    <int:header name="a"  expression="@call_api_a_GW(#root).payload" />
</int:header>

Does the trick for me. Thanks again.

温柔女人霸气范 2025-02-14 08:54:20

@Artem-Bilan建议使用&lt; enricher&gt;而不是&lt; header-enricher&gt;导致一个解决方案,该解决方案通过直接解决通道来避免Java界面签名。

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

我们可以从&lt; ronicher&gt;调用此频道。在这里,为简单起见,&lt; ronicher&gt;组件是链的一部分,但这不是要求:

<int:chain ...>

    <int:enricher request-channel="call_api_a" 
                  request-payload-expression="payload" >
        <int:header name="a" expression="payload" />
    </int:enricher>

</int:chain>

再次感谢指针。

@artem-bilan's suggestion to use <enricher> instead of <header-enricher> leads to a solution that obviates the Java interface signatures by addressing directly a channel.

<int:channel id            = "call_api_a" />
<int:chain   input-channel = "call_api_a" >
    ...
</int:chain>

We can call this channel from an <enricher>. Here, for simplicity, the <enricher> component is part of a chain, but that is not a requirement:

<int:chain ...>

    <int:enricher request-channel="call_api_a" 
                  request-payload-expression="payload" >
        <int:header name="a" expression="payload" />
    </int:enricher>

</int:chain>

Thanks again for the pointers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文