2014-09-27 28 views
0

我正在开发一个项目,我们决定添加一些使用jms和hornetq作为提供者的交互。
我对骆驼相当陌生,所以遇到一些问题,如果你可能指的是微不足道的。
目标是初始化连接工厂并添加jms组件。但是,据我所知,它不能直接在路由配置器中完成。所以我创建了camel-config.xml并将其放置到resources /目录。
我以下列方式填充它:在模式中找不到任何组件:jms

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:camel="http://camel.apache.org/schema/spring" 
     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"> 

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> 
     <property name="environment"> 
      <props> 
       <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop> 
       <prop key="java.naming.provider.url">jnp://localhost:1099</prop> 
       <prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop> 
      </props> 
     </property> 
    </bean> 

    <bean id="jmsQueueConnectionFactory" 
      class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiTemplate"> 
      <ref bean="jndiTemplate"/> 
     </property> 
     <property name="jndiName"> 
      <value>ConnectionFactory</value> 
     </property> 
    </bean> 

    <bean name="jms" class="org.apache.camel.component.jms.JmsComponent"> 
     <property name="connectionFactory" ref="jmsQueueConnectionFactory"/> 
    </bean> 

</beans> 

项目不使用Spring所以它是XML我发现,不使用弹簧的唯一的例子。 在路线配置器我用routeBuilder.from("jms:queue:top").to("...");

然而,当我开始它抛出FailedToCreateEndpointException并指出
“与架构没有找到组件:JMS”项目。
我想这个xml文件根本就没有用过,但我无法理解如何指向它。期待听到任何建议。

+0

这实际上*是*使用Spring,正如彼得说,它需要被引导或替换。但是,在其他任何事情之前,请确认您实际上是否添加了camel-jms依赖项。这是您错过类路径中的组件时所遇到的错误类型。 – kaqqao 2014-09-29 17:37:11

回答

1

<beans/> XML是一种Spring配置,必须以某种方式自举。您可以查看找到的的Tomcat ActiveMQ示例,说明如何在servlet环境中执行此操作。有一个特殊的看web.xml

<!-- location of spring XML files --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath:broker.xml, 
     classpath:camel-config.xml 
    </param-value> 
</context-param> 

<!-- the listener that kick-starts Spring, which loads the XML files and start our application --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

当然,你也可以使用一个唯一的Java设置如下:

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); 

ModelCamelContext context = new DefaultCamelContext(); 
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));