使用SpEL和regex的Kafka信道路由

使用SpEL和regex的Kafka信道路由,regex,spring,spring-integration,spring-el,Regex,Spring,Spring Integration,Spring El,希望基于SpEL regex组合路由到通道,以便来自不同主题/负载的多条消息可以路由到同一通道。 如上所述尝试,其他组合使用不同的路由器类型可用。不工作 <int:recipient-list-router input-channel="receiveMessageChannel"> <int:recipient channel="in_channel" selector-expression="headers['topic'] matches #{systemProp

希望基于SpEL regex组合路由到通道,以便来自不同主题/负载的多条消息可以路由到同一通道。 如上所述尝试,其他组合使用不同的路由器类型可用。不工作

<int:recipient-list-router  input-channel="receiveMessageChannel">
 <int:recipient channel="in_channel" selector-expression="headers['topic']  matches  #{systemProperties['env'] + '${in.msge.topic}' + '.*'}"/>
 <int:recipient channel="email_channel" selector-expression="headers['topic']  matches #{systemProperties['env'] + '${email.msge.topic}' + '.*'}"/>
 </int:recipient-list-router>
获取以下错误:

原因:org.springframework.expression.spel.spelparsexception:EL1049E:pos 37:在“.”之后出现意外数据:“'star*”

headers['topic']=mesge.getPayload.setHeaderstopic,testTopic


任何人都可以提供一些建议。谢谢。

matches参数必须是字符串。下面是正确的语法

selector-expression="headers['topic']  matches '#{systemProperties[env]}${in.msge.topic}.*'"
请注意,它不适用于虚线系统属性。你需要为这个添加引号

selector-expression="headers['topic']  matches '#{systemProperties[&quot;env.foo&quot;]}${in.msge.topic}.*'"/>
这与有点不同的原因是,在这种情况下,SpEL表达式的计算结果为一个值,该值在上下文初始化期间用作简单字符串


在本例中,我们需要计算一个字符串,该字符串在运行时作为另一个SpEL表达式的一部分使用-因此整个过程需要用“…”包围。

Hi@Gary感谢您的回答和解释。它工作正常。