【问题标题】:camel generic producer (to be routed via spring xml config)骆驼通用生产者(通过 spring xml 配置路由)
【发布时间】:2014-08-22 21:54:08
【问题描述】:

我想从 java 发送一条通用消息,然后由骆驼路由。到目前为止,消息总是转到 activemq 主题(示例 1),但将来我希望能够在不修改源代码(通过 spring xml 配置)的情况下更改路由(即将消息发送到 rest webservice)。所以我希望做〜类似〜示例2。我该怎么做?

示例 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>

【问题讨论】:

    标签: java xml spring apache-camel


    【解决方案1】:

    您可以使用属性占位符:http://camel.apache.org/using-propertyplaceholder.html - 然后不需要更改 java 源代码,但 uri 定义在 .properties 文件中,您可以轻松更改该文件

    【讨论】:

    • 也是个好主意,但我更喜欢我的解决方案(因为最终会有两种不同的 .xml 配置可以互换)
    【解决方案2】:

    好的,它开始工作了。直接使用其实很简单:component(http://camel.apache.org/direct.html)

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

    现在我可以发送消息了:

    producer.sendBody("Hello world!");
    

    并通过 Spring xml 配置路由它们,例如像这样:

     <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2018-01-27
      • 2012-10-27
      • 2018-07-28
      • 1970-01-01
      • 2017-03-10
      相关资源
      最近更新 更多