2014-07-02 40 views
1

我想從java發送一條通用消息,然後通過camel路由。到目前爲止,消息總是進入activemq主題(示例1),但將來我希望能夠在不修改源代碼(通過spring xml配置)的情況下更改路由(即將消息發送到其他web服務)。所以我希望做〜像〜例子2.我該怎麼做?駱駝通用生產者(將通過spring xml config路由)

例1:(它是如何這樣做的遠)

@EndpointInject(uri="activemq:topic:IMPORTANTEVENTS") 
ProducerTemplate producer; 
producer.sendBody("Hello world!"); 

例2:(它應該是怎樣的樣子 - 更多或更少)

@EndpointINject(uri="myevents") 
... (as above) 

XML配置:

<route id="SysoutRoute"> 
    <from uri="myevents"/> 
    <to uri="activemq:topic:IMPORTANTEVENTSS"/> 
</route> 

回答

3

您可以使用屬性佔位符:http://camel.apache.org/using-propertyplaceholder.html - 然後不需要更改java源代碼,但是uri被定義在一個.properties文件中,然後你可以很容易地修改它

+0

也是一個好主意,但我更喜歡我的解決方案(因爲將有兩個不同的.xml配置可在最後互換) – Alex

0

確定它工作正常。組件(http://camel.apache.org/direct.html

@EndpointInject(uri="direct:outMessage") 
ProducerTemplate producer; 

現在我可以發送郵件:通過S​​pring XML配置例如

producer.sendBody("Hello world!"); 

,並將它們路由它通過使用直接的實際上課很容易像這樣:

<route id="outMessage"> 
    <from uri="direct:outMessage"/> 
    <to uri="stream:out"/> 
    <to uri="activemq:topic:IMPORTANTEVENTS"/> 
    <to uri="restlet:http://localhost:8888/status/?restletMethod=post"/> 
</route>