我有一个Camel路由和一个使用when-choice语句的基于内容的路由。我正在使用带有正则表达式的JSONPath来比较传入数据中的一个名为topic
的元素,然后根据主题确定将其发送到哪个端点。
问题在于,无论topic
元素中的值是否与正则表达式匹配,骆驼总是执行第一选择。我还尝试过更改选择的顺序,无论它是什么,它始终会执行第一个选择。我在此JsonPath Evaluator中手动检查了正则表达式,并在那里得到了正确的结果。
很奇怪,我尝试使用Camel的简单语言来表达一个虚拟条件,并且在这种情况下,评估可以正确地表达文字,消息并不总是传递给首选。这使我认为我的正则表达式或Camel处理它们的方式有问题。
这是相关的骆驼路线:
<route id="receivePosition">
<from
uri="idsserver://0.0.0.0:9292/?sslContextParameters=#serverSslContext&attestation=1"/>
<convertBodyTo type="java.lang.String"/>
<log message="Received message ${body} with headers ${headers}"/>
<choice>
<when>
<jsonpath>[?(@.topic =~ /forklift\/.*\/position/i)]</jsonpath>
<log message="Routing message to forkliftPosition"/>
<to uri="forkliftPosition"/>
</when>
<when>
<jsonpath>[?(@.topic =~ /forklift\/.*\/acceleration/i)]</jsonpath>
<log message="Routing message to forkliftAcceleration"/>
<to uri="forkliftAcceleration"/>
</when>
<when>
<jsonpath>[?(@.topic =~ /forklift\/.*\/impact/i)]</jsonpath>
<log message="Routing message to forkliftImpact"/>
<to uri="forkliftImpact"/>
</when>
<otherwise>
<log message="Routing message to geoAcceleration"/>
<to uri="geoAcceleration"/>
</otherwise>
</choice>
</route>
这是我要发送的邮件的一些示例:
{"topic": "forklift/1/position", "message": {"x":"6.8052026806455945","y":"6.5546865012006075","z":"46.69778056906287"}}
{"topic": "forklift/1/impact", "message": {"date":{"nano":6541000,"epochSecond":1600761505},"impact":true}}
{"topic": "geolocation/1/acceleration", "message": {"x":"42.44249630338786","y":"13.492870450326972","z":"24.95959413495642"}}
{"topic": "forklift/1/position", "message": {"x":"41.86691902528943","y":"31.934653476220436","z":"47.43607241265882"}}
{"topic": "forklift/1/position", "message": {"x":"22.218576399047368","y":"17.14644029124392","z":"43.390649851176235"}}
{"topic": "forklift/1/position", "message": {"x":"46.268974377584456","y":"37.28146451988936","z":"20.679591417503058"}}
{"topic": "geolocation/1/acceleration", "message": {"x":"27.54178220678984","y":"40.329306970979886","z":"15.224365830285224"}}