Akka Camel和Spring

Sas*_*aXP 7 java spring apache-camel akka

我想结合Akka,Apache Camel,Spring,并且不知道如何在同一个项目中利用这三件事.

我成功了

1. write some working code with akka, akka-camel extension and camel routes(Java DSL)
2. use camel and spring (use java DSL but spring for transactions and etc..)
Run Code Online (Sandbox Code Playgroud)

现在我需要结合1和2.任何人都可以建议我实现这一目标的最简单方法吗?

编辑 有人说AKKA由于对象实例化中的冲突而不再支持Spring,如下面的链接 为什么akka的spring integration doc仅存在于1.3.1但不存在于下一版本

还有一个类似的问题是没有提供适当的解决方案,但帖子是使用Spring XML约2年 akka-camel 2.2.1路由定义

在一篇博客文章中(我现在无法理解该链接)已经描述了一种方法,总的来说,演员被定义并使用Akka方式以及处理Akka演员使用Spring进行连接的过程.但没有任何可靠的例子.

KDo*_*yle 1

我想你的#2 看起来像这样:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:ctx="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd >

  <!-- Camel route configuration -->
    <camelContext id = "testCamelRouteContext" xmlns="http://camel.apache.org/schema/spring">
        <route id="test_data_webservice">
            <from uri="jetty:http://localhost:8888/myTestService"/>
            <log logName="HTTP LOG" loggingLevel="INFO" message="HTTP REQUEST: ${in.header.testdata}"/>
            <process ref="myTestService"/>
        </route>
    </camelContext>

    <context:annotation-config />

    <bean class="com.package.service" id="myTestService"/>

        <bean id="genericDao" class="com.dao.Impl">
        <property name="dataSource" ref="datasource" />
    </bean>

    <bean id="testingDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        datasource stuff
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

是否可以通过Akka获取这个camel上下文?就像是。

添加您的 Akka 配置:

akka.camel.context-provider="myNewContext"
Run Code Online (Sandbox Code Playgroud)

新的 ContextProvider 类:

class myNewContext extends ContextProvider{
    override def getContext(system: ExtendedActorSystem): SpringCamelHybridContext
}
Run Code Online (Sandbox Code Playgroud)

我猜测这就是 Spring 和 Akka 之间可能发生 Bean 注入冲突的地方。我以前从未使用过 Akka,所以我的回答很简单,但我想看看是否可以为您提供一些帮助。