akka-camel 2.2.1 route definition using Spring XML

白昼怎懂夜的黑 提交于 2019-12-22 19:48:41

问题


I am using akka-camel 2.2.1 and need to configure routes to and away from Consumer and Producer actors, respectively. I am currently defining routes and adding them to the internal Camel context within the CamelExtension programmatically like so:

camel.context.addRoutes(new RouteBuilder { 
    def configure() = {
      from("file:/tmp?include=whatever.*.log&noop=true&sendEmptyMessageWhenIdle=true")
        .split(body(classOf[String]).tokenize("\n"))
        .streaming()
        .to("seda:input-route")

      from("seda:update-route")
        .to("bean:db-update-bean?method=process")
  }})

I have an Actor that extends Consumer which reads from "seda:input-route" via its endPointUri, and another Actor that extends Producer that writes to "seda:update-route". The "db-update-bean" in defined in a Spring applicationContext.xml like so:

<bean id="db-update-bean" class="nz.co.whatever.DBUpdate">
    <constructor-arg ref="jdbcTemplate"/>
    <constructor-arg value="some_other_constructor_arg"/>
</bean>

The Spring context is loaded and started in a supervisor Actor started by akka.Main. However (and understandably), Camel is unaware of this Spring context, and thus went to great lengths to inform me that it had no clue what the "db-update-bean" was:

2013-10-11 08:55:09,614 [SedaConsumer ] WARN Error processing exchange. Exchange[Message: 1378642997698,27684,true,57.000000,0.750000,97]. Caused by: [org.apache.camel.NoSuchBeanException - No bean could be found in the registry for: db-update-bean]

Of course, I could programmatically add the components to the akka-provided CamelContext, or else do something like this:

    from("seda:update-route")
      .bean(new DBUpdate(jdbcTemplate, "gps_temp_status"), "process")

but I would rather use Spring to define beans. Clearly, the CamelExtension needs to use the Spring-defined CamelContext rather than creating one of its own.

Furthermore, and more importantly, I would like to externalize the definition of the Camel routes into the same applicationContext.xml within a <CamelContext/> tag. Accoring to articles such as https://weblogs.java.net/blog/manningpubs/archive/2013/02/13/akka-and-camel, it seems the way to do so is to instantiate a "camel-service" bean and inject the Spring-defined CamelContext as so:

<camel:camelContext id="camelContext">   
</camel:camelContext>

<akka:camel-service id="camelService">                             
    <akka:camel-context ref="camelContext" />
</akka:camel-service>

Here is where the wheels come off. According to Roland Kuhn's reply in Why spring integration doc for akka exists only for 1.3.1 but not for next versions, the akka-spring library is not included in Akka 2.2.1, and thus there is no Spring namespace handler for akka, and I'm unable to instantiate this camel-service bean. Though not for lack of trying. Or cursing.

And so (finally), the question: How does one define Camel routes in Spring XML whose endpoints can be used by Consumer or Producer Actors using akka-camel 2.2.1 without akka-spring? Does one instantiate a Factory bean that produces a CamelService with a CamelContext injected or some other such witchcraft? Secondarily (but related) how can I use Spring to instantiate beans to be referenced in camel routes if I am forced to define them via a RouteBuilder?

Thanks in advance.

来源:https://stackoverflow.com/questions/19306531/akka-camel-2-2-1-route-definition-using-spring-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!