2015-10-19 84 views
0

想要基于SpEL正则表达式组合路由到通道(以便来自不同主题/有效负载的多个消息可以路由到同一通道)。 试用上面和其他组合使用不同的路由器类型available.Not工作。使用SpEL和正则表达式的卡夫卡通道路由

<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.SpelParseException:

致EL1049E:(POS 37):意外数据之后 '': '星号(*)'

标题['topic'] = mesge.getPayload()。setHeaders(“topic”,“testTopic”);

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

回答

0

matches参数必须是String。下面是正确的语法...

selector-expression="headers['topic'] matches '#{systemProperties[env]}${in.msge.topic}.*'" 

注意,它不会为虚systemProperties工作。您需要添加引号为...

selector-expression="headers['topic'] matches '#{systemProperties[&quot;env.foo&quot;]}${in.msge.topic}.*'"/> 

的原因,这是this answer有一点不同是因为,在这种情况下,规划环境地政司表达式求是上下文初始化过程中作为一个简单的String值。

在这种情况下,我们需要评估一个String,它在运行时用作另一个SpEL表达式的一部分 - 因此整个事情需要被'...'包围。

+0

嗨@Gary 感谢您的答复和解释。它工作正常。 – sam