2014-07-02 39 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>