2015-10-19 80 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