gpt4 book ai didi

spring - Camel - 在 Spring DSL 中使用属性

转载 作者:行者123 更新时间:2023-12-01 20:17:08 24 4
gpt4 key购买 nike

我试图在我的处理方法中设置一些属性,但我无法弄清楚如何在 xml 中使用这些属性,就像我可以通过使用语法轻松使用 xml 中的 header 值:${in. header.myKey}

这是我的代码:

    <route>
<from uri="activemq:queue:start.queue" />
<to uri="stream:out" />
<process ref="jsonProcessor"></process>
<to uri="bean:validateInputIdentifiers?method=validation(${in.property.SourceMap}, ${in.property.DestinationMap})" />
</route>

这里 in.property.SourceMap 是未知函数。正确的方法是什么?如果它是类似于 header 的东西那就太好了。另外,我只想使用属性而不是 header ,因为 header 的值可能不会在我的路由中持续存在。

这里是处理方法代码:

@Override
public void process(Exchange exchange) throws Exception {
List<Map<String, String>> body = exchange.getIn().getBody(List.class);
Map<String, String> sourceMap = body.get(0);
Map<String, String> destinationMap = body.get(1);
exchange.setProperty("SourceMap", sourceMap);
exchange.setProperty("DestinationMap", destinationMap);

}

请提供解决方案。

最佳答案

您的问题可能有多种解决方案组合。

示例属性键和值。

<cm:property name="app.user" value="PROD008"/>

在路由中,如果你想设置具有属性值的 header 。使用下面的代码片段。

<setHeader headerName="password">
<simple>${properties:app.user}</simple>
</setHeader>

如果您想使用属性,可以使用下面的代码片段。

<to uri="{{some.endpoint}}"/>

对于您的示例:如果属性是 SourceMap 和 DestinationMap,您可以使用以下任何一个。

1. <to uri="bean:validateInputIdentifiers?method=validation(${property.SourceMap}, ${property.DestinationMap})" />

2. <to uri="bean:validateInputIdentifiers?method=validation({{SourceMap}},{{DestinationMap}})" />

如果您想使用 header 而不是属性,请使用下面的代码片段。

<to uri="bean:validateInputIdentifiers?method=validation(${header.SourceMap}, ${header.DestinationMap})" />

关于spring - Camel - 在 Spring DSL 中使用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36911906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com